Search code examples
wxwidgets

wxBitmap::LoadFile fails in Windows


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?


Solution

  • 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.