Problem with bitmaps

Hello, I'm completely new to allegro and I'm writing a program to dither image files. Unfortunatelly it's a task for programming classes and I couldn't choose any other library for that (normally I'd use something that is created specially for this purpose). The problem is as follows:

I load the bitmap from file:
image = al_load_bitmap(imagePath.c_str());
then I display it:

Until then everything goes fine, however there's a problem later. Whenever I use al_draw_pixel, it draws the pixels successfuly and even displays the image after it's done, however after I try to save the same image I just modified, or alter it using another function, it does not work on the modified image, but on the image that was initially loaded. I.e. when I save it, even though it's modified, I obtain saved copy of the source file. What can be the source of this problem? At every attempt to modify the bitmap, I use al_lock_bitmap(image,al_get_bitmap_format(image), ALLEGRO_LOCK_READWRITE);
and then once it's done, I unlock it.

Please help me, it's a real struggle for me and my time is very limited so that I cannot unfortunately read the whole documentation :(

Dizzy Egg

Are you setting the bitmap to be the one that's being drawn to? al_set_backbuffer or whatever? Because if not, im guessing it draws the pixel to the screen, on top of you image (not actually in it...)

..I could be wrong!


You are at the very least wrong in that you probably meant al_set_target_bitmap :)


Unfortunately neither of the suggestions seem to be working. The procedure is as follows:

1.load bitmap and display it
2.convert to grayscale and display it ( al_draw_pixel used here, together with locking the bitmap and unlocking it after it's done)
3.Dither the image and display it(the same procedures as in 2.)
4.Save the image.

1. works fine and displays
2. works fine and displays
3. instead of working on grayscale image, it works on the source image and displays
4. saves the file that was loaded in 1. but it is not changed...

I fixed it and the problem was that after unlocking the bitmap, it goes back to the previous state. Now the problem is that saving behaves really strange - it always saves a black bitmap... If I unlock the bitmap before saving, it saves the source (uneditted) file.


Show some code. It should be the bare minimum compiling program that exhibits the problem you are having.
When pasting it into your message, use <code> tags so that it is easy for us to view.

Dizzy Egg

It's sort of kind of almost maybe not really almost not quite near impossible to create something in memory, save it to a hard drive, and then open it to find it's not the thing you saved. What I'm trying to say, in the nicest way possible, is you're definitely doing something a) wrong b) miraculous.

Show us your code, we will do nothing but point out why whats happening is happening; it'll help! 8-)


My wild guess is that the image is converted and drawn to the display, but not to the bitmap that is being saved. That would explain getting a black (or blank) bitmap on saving.

Thread #614256. Printed from