[A5] How to load an image from memory ?


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.


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

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.


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

Thread #613273. Printed from Allegro.cc