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.

Windows / AGK (AGKSharp) - LoadImage from byte array.

Years of Service
User Offline
Joined: 18th Sep 2008
Posted: 28th Sep 2021 13:58

I am trying to find out if there is a way to load an AgkImage from a byte array rather than from a file directly?
I don't want to ship all my assets in a folder along with the game and I am exploring ways I can embed images as byte arrays and load them like that.
Is this possible?

Also, is there a way to convert a .Net Image to an AGKImage?

From my Googling it seems neither of this is possible, but I'd like to be sure.

A thousand thanks.
Years of Service
User Offline
Joined: 30th Jan 2009
Location: Cambridge
Posted: 28th Sep 2021 16:07
Hi TenaC

Yes you can. You need to put your byte array into a memblock, then use the memblock command CreateImageFromMemblock.

If you look at the help page for this command there is an example with code.

The above command is for bitmaps. There is also a command CreateImageFromPNGMemblock that does the same for PNG's.

I would guess as long as your .Net image is either a bitmap or PNG, you might be able to get the raw bits, put them into a memblock. Maybe you could use a MemoryStream or something like that to save the image to? Then read the bits from the MemoryStream into an AppGameKit memblock, then use one of the above commands to create an AppGameKit image from that?

Cheers, Glob
Valued Member
Gold Codemaster
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 29th Sep 2021 11:33

If you are looking for some kind of asset protection.
Then since the last update (March 2021) you can use the new functions Agk.Assign to add password protected zip files to the agk filesystem. (only for AgkSharp)
All following commands like LoadImage look first in this zip file if it finds the designated file and loads it.
And no - the zip file is not unpacked somewhere on the harddisk. the data is read directly from the zip file.

If your question had other reasons then just forget this post.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2021-10-25 20:03:50
Your offset time is: 2021-10-25 20:03:50