Can't load PNG files in wxImage? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
void.pointer
Knows some wx things
Knows some wx things
Posts: 34
Joined: Fri Nov 14, 2008 6:15 pm

Can't load PNG files in wxImage?

Post by void.pointer »

Hi,

For some reason I can't load my PNG file into a wxImage object.

I do this:

Code: Select all

wxImage image( wxT("overlay1.png") );
assert( image.IsOk() );
I've attached the PNG file if anyone wants to give it a quick test. The assertion above fails and that's how I know it isn't working. Can someone download my PNG file (attached) and give this a test? Why isn't it working? It works for BMP files for sure.

I'm using the latest stable version of wxWidgets as of about 2 or 3 days ago.
Attachments
overlay1.png
overlay1.png (196 Bytes) Viewed 3148 times
stevelam
Earned some good credits
Earned some good credits
Posts: 114
Joined: Fri Apr 14, 2006 11:01 am

Post by stevelam »

Do you call wxImage::AddHandler(wxPNGHandler) or wxInitAllImageHandlers? If not you will need to as they initialise support for various image handlers. I think the reason BMPs are working is because that handler is added by default :)
void.pointer
Knows some wx things
Knows some wx things
Posts: 34
Joined: Fri Nov 14, 2008 6:15 pm

Post by void.pointer »

stevelam wrote:Do you call wxImage::AddHandler(wxPNGHandler) or wxInitAllImageHandlers? If not you will need to as they initialise support for various image handlers. I think the reason BMPs are working is because that handler is added by default :)
Well that's stupid. The class documentation doesn't even mention this. Sigh. Why do the exceptions not tell me this? They should say, "Invalid format. Did you call wxInitAllImageHandlers()?"

Thanks for your help!
Post Reply