Creating a wxIcon from a bitmap (.bmp or .png) 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
gillyames
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 16, 2011 5:51 pm

Creating a wxIcon from a bitmap (.bmp or .png)

Post by gillyames »

Hi everyone,
I'm a brand new user, been going for all of a week, so any help would be really useful and hopefully this will be easily fixed!
i'm trying to create an icon for my frame, and following the wxWidgets book I typed:

wxIcon limeIcon;
wxBitmap bitmap(wxT("LimeIcon24_24.png"), wxBITMAP_TYPE_PNG);
limeIcon.CopyFromBitmap(bitmap);
SetIcon(wxIcon(limeIcon));

This builds but I get a "No image handler for type 15 defined" warning. I know that the type is included in the enumeration list in gdicmn.h, as well as wxBITMAP_TYPE_PNG_RESOURCE, but it isn't in any other bits of code that I can search in.

so I tried :

wxIcon limeIcon;
wxBitmap bitmap(wxT("LimeIcon24_24.bmp"), wxBITMAP_TYPE_BMP);
limeIcon.CopyFromBitmap(bitmap);
SetIcon(wxIcon(limeIcon));

which built and ran with no warnings but did not display the icon.

I'm using Windows XP and visual studio express 2010 to program in.

Any help would be most appreciated!
thanks in advance,
Gilly Ames
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

You should initialise all image handlers before trying to import images (::wxInitAllImageHandlers)

Take a look at the following link for more info : http://docs.wxwidgets.org/2.8/wx_appini ... gehandlers
gillyames
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 16, 2011 5:51 pm

Post by gillyames »

Thanks for the reply, have tried the Initialise all option, which did stop the warning, but the picture was still not displayed.
also corrected the line:
SetIcon(wxIcon(LimeIcon))
to just
SetIcon(LimeIcon) (since the icon was already created)
this is all done in the frame construnctor so there is no need for frame-> etc.
have now also tried the xpm route, i.e creating a .xpm file and compiling that, which also didn't work, but still not errors or warnigns in the build. am starting to suspect the size - is 24x24 not 16x16. could this be the problem?
Cheers,
Gilly Ames
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre »

I don't think the size should be a problem. What is your code for the xpm version ? It should simply be something like this :

Code: Select all


#include "my_icon.xmp"

...

SetIcon(wxIcon(my_icon_xpm));
gillyames
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 16, 2011 5:51 pm

Post by gillyames »

yes that's right:

#include "LimeIcon24_24.xpm"
SetIcon(wxIcon(LimeIcon24_24_xpm));

also tried:

wxIcon LimeIcon(LimeIcon24_24_xpm);
SetIcon(LimeIcon);

neither of which produce errors or pictures.
Cheers,
Gilly
gillyames
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 16, 2011 5:51 pm

Post by gillyames »

Hiya,
Many thanks for your replies, have managed to make it work using a 16x16 pixel image. Perhaps this is a bug?
Cheers,
Gilly
Post Reply