converting to a bitmap
shadyvillian

In my program I download a image from a server into memory now I want to take a pointer and turn it into an ALLEGRO_BITMAP. Is there special way to do that or does allegro have something that I can use to do that? I tried casting it but it didn't work.

Thomas Fjellstrom

You can make a memfile (using the memfile addon) from the data, and use al_load_bitmap_f.

Or save it to disk and al_load_bitmap it.

shadyvillian

Thanks I'll give it a shot. I can't save it to the disk for performance issues but I think the first one will work. I'm getting a crash when I try to draw it. Does this look valid?

selectedCard.Load(al_load_bitmap_f(al_open_memfile(chunk.memory, chunk.size, "w"), ""));

The Load function takes a parameter of ALLEGRO_BITMAP.

Thomas Fjellstrom

You should check for failure in both al_open_memfile and al_load_bitmap_f.

Trent Gamblin

Plus that's a memory leak (leaking from al_open_memfile).

shadyvillian

How do you know it's a memory leak?

Trent Gamblin

al_open_memfile (click for docs) returns an ALLEGRO_FILE that has to be closed with al_fclose, which frees up the memory used.

shadyvillian

So I have to use memfile open close it then use load bitmap f?

Thomas Fjellstrom

You'd close the memfile after using load_bitmap_f. Also free up the memory buffer you have the image in.

shadyvillian

is this good enough for freeing memory or is there more i need to do? Everytime I call the function my memory usage goes up :-/

al_fclose(file);
    free(chunk.memory);

Thread #611109. Printed from Allegro.cc