Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » converting to a bitmap

This thread is locked; no one can reply to it. rss feed Print
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
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

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
avatar

You should check for failure in both al_open_memfile and al_load_bitmap_f.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

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
avatar

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
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

shadyvillian
Member #12,426
December 2010

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);

Software Engineer by day, hacker by night.

Go to: