How do I load images with wxImage?

Started by
1 comment, last by Oralloy 18 years, 3 months ago
I do something like:

wxImage img;
img.LoadFile("thisfile.jpg", wxBITMAP_TYPE_JPEG);

wxBitmap bm(img);

I get a "no handler found for image type" error though. It works fine when I load a .bmp using wxBitmap though. Help?
Hey babe.
Advertisement
wxWindows has image handlers, that handle the loading of various image file formats. I don't recall the method name off-hand (I'm sure you can find it quickly in the documentation), but there is a method you can call that will initialize all known image handlers. Just call that function once in the beginning of your app, and you should be good to go.
Adding an image handler is very easy. Here is an example to get you started:
wxImageHandler * jpegLoader = new wxJPEGHandler();wxImage::AddHandler(jpegLoader);wxBitmap bitmap;bitmap.LoadFile("thisfile.jpg", wxBITMAP_TYPE_JPEG); 

Note that some file formats have handlers that do not support saving of images (eg. GIF).

This topic is closed to new replies.

Advertisement