Canopus
Canopus

Reputation: 7447

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?

Upvotes: 3

Views: 2394

Answers (2)

SteveL
SteveL

Reputation: 1821

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.

Upvotes: 4

jholl
jholl

Reputation: 2084

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

Upvotes: 1

Related Questions