|
converting to a bitmap |
shadyvillian
Member #12,426
December 2010
|
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. Software Engineer by day, hacker by night. |
Thomas Fjellstrom
Member #476
June 2000
|
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
Member #12,426
December 2010
|
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. Software Engineer by day, hacker by night. |
Thomas Fjellstrom
Member #476
June 2000
|
You should check for failure in both al_open_memfile and al_load_bitmap_f. -- |
Trent Gamblin
Member #261
April 2000
|
Plus that's a memory leak (leaking from al_open_memfile).
|
shadyvillian
Member #12,426
December 2010
|
How do you know it's a memory leak? Software Engineer by day, hacker by night. |
Trent Gamblin
Member #261
April 2000
|
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
Member #12,426
December 2010
|
So I have to use memfile open close it then use load bitmap f? Software Engineer by day, hacker by night. |
Thomas Fjellstrom
Member #476
June 2000
|
You'd close the memfile after using load_bitmap_f. Also free up the memory buffer you have the image in. -- |
shadyvillian
Member #12,426
December 2010
|
|