- Online Community Forums » Programming Questions » Loading a PNG from a DATAFILE

This thread is locked; no one can reply to it. rss feed Print
Loading a PNG from a DATAFILE
Member #8,173
December 2006

I'm trying to load a PNG image that I saved as "Other" data in the Allegro datafile to a OpenLayer Bitmap. I'm definately not doing it right since it's giving a runtime error in the Bitmap constructor.

Here is how I'm trying to do it.

DATAFILE *dataFile = load_datafile("test data.dat");
BITMAP *bitmap = load_memory_png(dataFile[0].dat, sizeof(dataFile[0].dat), 0); //loadpng library function
Bitmap *newBitmap = Bitmap(bitmap, HAS_ALPHA_CHANNEL);

I'm sure someone knows the right to do this.

EDIT: Well I fixed it, didn't realize loadpng had functions to help with that.

Kitty Cat
Member #2,815
October 2002

FYI, the problem was the .dat pointer is only four bytes, so you're basically telling loadpng that the png data is only 4 bytes long. That fails and returns NULL, which means the Bitmap doesn't get made. For the size of the data, you want to use the .len field.

"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Go to: