- Online Community Forums » Programming Questions » [A5] How to load an image from memory ?

This thread is locked; no one can reply to it. rss feed Print
[A5] How to load an image from memory ?
Member #15,298
September 2013


I'm in a situation where speed is very important. I'm analyzing a continuous stream of images that are in memory. What I want to do is: load and image into a bitmap, analyse it pixel-per-pixel, and do other stuff...

Well, I'm here because I'm stuck with the first part...

So, Could anyone tell me How to load an image that "sits" in memory?

Also, any future recommendations on pixel-per-pixel analysis is also appreciated. Particularly, What functions should one use for the process to be fast.

Any Help Appreciated.

Member #15,203
June 2013

al_load_bitmap() loads an image into memory:

ALLEGRO_BITMAP *my_image = al_load_bitmap("image.png");

You can use al_get_pixel() to read each individual pixel in a nested loop, but it's going to be SLOW... make sure you lock the bitmap before doing so (it will speed it up a bit):

al_lock_bitmap(my_image, al_get_bitmap_format(my_image), ALLEGRO_LOCK_READONLY);

Thomas Fjellstrom
Member #476
June 2000

You can open a chunk of memory using the al_open_memfile function from the memfile addon. then you can use the al_load_bitmap_f function to load the image from an open file handle.

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" --

Member #15,298
September 2013

Thank You Very Much Thomas Fjellstrom. I don't know what I would do without You!

Go to: