Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Fail To Create File?

Author
Message
Scribble
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 20th Sep 2022 03:02 Edited at: 20th Sep 2022 03:19
Hello.
I've been trying to manipulate image file in memblock, and then produce a new image file from said memblock.
But the image file produced can't be read, and had strange size (4.1mb) while the original file is only 53kb.

What I try to do:
- load image
- Create memblock from said image
- Copy each memblock bytes to an array of same size
- Copy bytes from the array to a NEW memblock
- CreateFileFromMemblock to produce a new jpeg image file

Now, I've also created a new image with CreateImageFromMemblock from the NEW memblock, and can texture a sprite with it and display it.
But I just seems to fail to create a new image file from the same NEW memblock.
The resulting file seems to be corrupted or something. It doesn't matter if I create the new image file using CreateImageFromMemblock or the 'traditional' way of openToWrite to a new file, the result is the same. I didn't even modify the memblock.

What did I do wrong?

Here's the example project. Thanks in advance.

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Sep 2022 04:24 Edited at: 20th Sep 2022 04:35
why cast to float?

why make an array of integers?

consider the memblock itself as the array to do whatever you want to the bytes, like convert an image to grayscale:



i hope that helps?
Scribble
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 20th Sep 2022 04:43 Edited at: 20th Sep 2022 04:46
@Virtual Nomad

Yeah, the float and array are kinda redundant thing I did just to see if the array can store the info. And it seems it can.
And I can even make a new memblock out of data from the array, and make a new image from that second memblock, and used that image to texture a sprite.

But the problem is, no matter what I did, I just can't create a new image file from the memblock.
I even skipped all the steps, and only try to CreateFileFromMemblock from the freshly-created memblock, basically making a carbon copy of that original file.
My code now literally only have these lines, nothing else, but it still fail to produce a valid image file:



Any idea why a valid file cannot be produced? Can you reproduce the 'error'?



EDIT: SaveImage() can produce an image file. But CreateFileFromMemblock and WriteByte can't.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 20th Sep 2022 05:24 Edited at: 20th Sep 2022 05:29
This post has been marked by the post author as the answer.
i'm pretty sure you're trying to save raw image data in the guise of a compressed jpg = no go.

as i understand it, when the jpg is loaded in, it's automatically converted to (what i call) raw image data and doesn't maintain the jpg compression while you're trying to output that (uncompressed) data as a (compressed) jpg. your image viewer is expecting a jpg format inside (based on the file extension) and it's not there.

something along those lines.
Scribble
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 20th Sep 2022 05:31 Edited at: 20th Sep 2022 05:32
@Virtual Nomad

Ah I see. So there's no way to produce a image file from a memblock in AppGameKit, without compressing it first and churn it out with SaveImage().
Thanks for the clarification. I'll proceed with that in mind.
blink0k
Moderator
11
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Sep 2022 22:28 Edited at: 20th Sep 2022 22:30
Quote: "So there's no way to produce a image file from a memblock in AppGameKit, without compressing it first and churn it out with SaveImage()."

I don't think that is true. I have created images using AppGameKit many times


Nice VN. I think that GreyScale converter would be handy in snippets

Login to post a reply

Server time is: 2024-04-19 08:17:45
Your offset time is: 2024-04-19 08:17:45