tags:

views:

17

answers:

2

I am trying to load an Image file of type .xpm into the wxBitmap Object using LoadFile method. The following call fails

wxBitmap aBitmap;
aBitmap.LoadFile(strIconPath,wxBITMAP_TYPE_XPM);

with the error

No image handler for type wxBITMAP_TYPE_XPM defined.

Whereas, if I load it by including the xpm file and using it as shown below, it works.

#include "Icon.xpm"

wxBitmap aBitmap;
aBitmap.CopyFromIcon(wxIcon(Icon_xpm));

What is the problem with the first implementation?

+1  A: 

Try adding ::wxInitAllImageHandlers(); before the LoadFile call or changing the image type specified in the LoadFile call to wxBITMAP_TYPE_ANY.

jholl
+1  A: 

If you only want to use XPM files then wxImage::AddHandler(new wxXPMHandler); should fix it, otherwise wxInitAllImageHandlers(); is easier for multiple image types. Both of these need to be called before you try to load the file.

SteveL