Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Unable to save to png..

This thread is locked; no one can reply to it. rss feed Print
Unable to save to png..
devo_au
Member #15,282
August 2013

Hello,

Got a problem, When I call al_save_bitmap("something.bmp", myimage); it saves my image to a bmp file no problem. But when I try al_save_bitmap("something.png", myimage); I get a .png file with 0 bytes..

My code has al_init_image_addon() so I don't know why I cant save to .png. Would be nice if I could as .png is more memory efficient. Thanks

it wasn't me, it was other kids

SiegeLord
Member #7,827
October 2006
avatar

What OS and Allegro version are you using?

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

devo_au
Member #15,282
August 2013

Allegro v 5.10
Windows 8 64

it wasn't me, it was other kids

SiegeLord
Member #7,827
October 2006
avatar

That sounds like you've compiled it yourself. If so, try recompiling with cmake -DWANT_NATIVE_IMAGE_LOADER=off .. . This will turn off the native loaders and force Allegro to use libpng.

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

devo_au
Member #15,282
August 2013

Sorry my bad, im using 5.0.10. I didn't have to compile it, just put the files into the directories and off I went.

it wasn't me, it was other kids

SiegeLord
Member #7,827
October 2006
avatar

Oh, nvm. Where did you get these binaries? I'm going to try to reproduce this.

EDIT: Trying things out with the MinGW 4.7 binaries from a.cc, this program works fine for me:

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

int main()
{
  al_init();
  al_init_image_addon();
  ALLEGRO_BITMAP* bmp = al_create_bitmap(256, 256);
  al_set_target_bitmap(bmp);
  al_clear_to_color(al_map_rgb_f(1, 0.2, 0.5));
  al_save_bitmap("test.png", bmp);
  return 0;
}

One last thing to try would be to link in the debug version and look at the allegro.log. In there, if Allegro is using the libpng backend, you should hopefully see some lines starting with "PNG error".

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

devo_au
Member #15,282
August 2013

Just tried your code with VC++ 2010 express in a new project.
It worked :/
It created the 256 x 256 magenta square png file..
Ran my original code again, with .png extention, still creates
0 byte png files. Checked allegro.log, all i found is relating to .png is
[ 24.22865] Failed loading help.png with .png handler.

it wasn't me, it was other kids

SiegeLord
Member #7,827
October 2006
avatar

That's very puzzling... it seems that in your program you can't even load PNGs! Something's very wrong. I don't quite understand how the test program can work while your program doesn't though... are you linking to the same libraries and have the same DLLs in the same place? Clearly, al_init_image_addon does something, since that error message only comes up if it was at least partly successful (as it managed to register the .png handler).

Sorry about this... the debugability of the IO routines has always been a pain point.

How big is your project? Is it an option for you to share the source?

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

devo_au
Member #15,282
August 2013

Unfortunately I cant post the project, it is big and has a lot of art that isn't my own in it. I have been experimenting with it though. I pasted your code into the project and run it. It created a png file of the same dimensions but it had no color this time.. Don't know if that means anything.

I have tried to replicate the problem in another project, but your code works in perfectly every time so far. I'm stuffed if I know what's going on. Might just give up and go with the bmp output or maybe batch convert to png.

it wasn't me, it was other kids

Go to: