- Online Community Forums » Programming Questions » loading bitmap trouble

This thread is locked; no one can reply to it. rss feed Print
loading bitmap trouble
Member #14,852
January 2013

Good afternoon, I have the following problem when I want to load the image mk.png the program snaps, and it's not the program because you can load other images even load the same image but changing the background in this case mkasd.png. in the version 5.0.10 ther was no problem. I'm using the current version vstudio2015 allegro5_1_12 so do i need to do somting else befor loading the image?.

sorri for the bad inglesh

this is my code

#include "allegro5\allegro5.h"
#include "allegro5\allegro_image.h"
#include <iostream>

int main()

display = al_create_display(640, 480);
if (display == nullptr)
al_clear_to_color(al_map_rgb(0, 0, 0));
ALLEGRO_BITMAP *img = al_load_bitmap("mk.png");
al_draw_bitmap(img, 0.0, 0.0, 0);
return 0;

Member #7,827
October 2006

I just tried your code with MSVC 2015 and the 5.1.12 32 and 64 bit binaries, and it worked ok (at least with my bitmap). Could you make sure that your bitmap is where you expect it to be (also perhaps try using an absolute path, just to be sure).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Member #14,852
January 2013

yes the code works but when i tried this bitmap (mk.png) it breaks

Member #358
May 2000

This .png is missing its CRC value, so is basically invalid. We could make Allegro read it anyway (we can instruct libpng to read on instead of error out) - but the downside is, if we do that we are likely to read in actually broken png files as well.

Best way is to simply open your .png in an image editor and save it again, then it will be fine.

elias@T440s:/tmp$ pngcheck -v mk.png 
File: mk.png (8826 bytes)
  chunk IHDR at offset 0x0000c, length 13
    363 x 475 image, 8-bit palette, non-interlaced
  chunk PLTE at offset 0x00025, length 768: 256 palette entries
  chunk tRNS at offset 0x00331, length 256: 256 transparency entries
  chunk IDAT at offset 0x0043d, length 7725
    zlib: deflated, 32K window, default compression
  chunk IEND at offset 0x02276, length 0
:  EOF while reading CRC value

[edit:] Actually, you can specify special handling for CRC errors, this patch would make Allegro ignore them:

1diff --git a/addons/image/png.c b/addons/image/png.c 2index 97badd0..9f014de 100644 3--- a/addons/image/png.c 4+++ b/addons/image/png.c 5@@ -62,7 +62,7 @@ static void read_data(png_structp png_ptr, png_bytep data, png_uint_32 length) 6 { 7 ALLEGRO_FILE *f = (ALLEGRO_FILE *)png_get_io_ptr(png_ptr); 8 if ((png_uint_32) al_fread(f, data, length) != length) 9- png_error(png_ptr, "read error (loadpng calling al_fs_entry_read)"); 10+ png_warning(png_ptr, "read error (loadpng calling al_fs_entry_read)"); 11 } 12 13 14@@ -110,6 +110,8 @@ static ALLEGRO_BITMAP *really_load_png(png_structp png_ptr, png_infop info_ptr, 15 16 ALLEGRO_ASSERT(png_ptr && info_ptr); 17 18+ png_set_crc_action(png_ptr, PNG_CRC_WARN_USE, PNG_CRC_WARN_DISCARD); 19+ 20 /* The call to png_read_info() gives us all of the information from the 21 * PNG file before the first IDAT (image data chunk). 22 */

"Either help out or stop whining" - Evert

Member #14,852
January 2013

a ok thanx

Go to: