Portable Network Graphics in menu items

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
gekkehenkie
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jan 19, 2006 3:01 pm

Portable Network Graphics in menu items

Post by gekkehenkie »

According to the documentation, support for the alpha component of images is available in recent versions of wxWidgets, but there doesn't seem to be any way to use PNG images with alpha bits in menu items (I have no idea if this is the same for other controls as well). Images with translucent bits are always shown as black instead of letting the background color get through.

Is it really not supported or am I just overlooking something?
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

I use the following code:

Code: Select all

#ifdef __WXMSW__
	{
		if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32)
			wxSystemOptions::SetOption(wxT("msw.remap"), 2);
		else
			wxSystemOptions::SetOption(wxT("msw.remap"), 0);
	}
#endif //__WXMSW__
You can look at the detailed info about wxSystemOptions.
gekkehenkie
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jan 19, 2006 3:01 pm

Post by gekkehenkie »

Sadly, that doesn't work for me.

(I've got my display depth set to 32 bpp and I'm using XP, so that's not the issue)
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

I also have a 32bpp screen on WinXP and it works well.
Can you send me one of your PNG images by private message/email? I will look at it.
gekkehenkie
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jan 19, 2006 3:01 pm

Post by gekkehenkie »

Here's a PNG image that doesn't work:

Image
(just a test icon I've temporarily taken from the tango project)
eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco »

I believe on versions of Windows before XP (98, 2000, etc.) if the alpha channel isn't 0x00 or 0xFF (on or off) for every "pixel" of the alpha channel it does this. Basically, you have to use your alpha channel as an alpha mask. If anyone knows any way around this I'd love to hear it as well.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

To expand on eco's reply, your PNG is guilty of having an alpha channel with values other than 0x00 and 0xFF. One way of fixing this if you have GIMP, is to open the image, go to Layer->Transparency->Threshold Alpha and use any value you want that works best for you. That will force every pixel in the alpha channel to be changed to a value of 0x00 or 0xFF depending on what it's original value was.

I've taken your PNG and done this for you as an example, see if this one works for you: Image

It's still possible that your problem isn't related though since your on XP, but you will have to take that into consideration for non-XP users.
gekkehenkie
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jan 19, 2006 3:01 pm

Post by gekkehenkie »

Yes, that works, but it misses the point of why I'm using PNG images: I'd like my icons to be anti-aliased. So trashing the alpha channel of my images is unfortunately not really an option.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

If it comes down to it, you could still pull this off not only on WinXP, but on other platforms as well by using this trick: http://forums.wxwidgets.org/viewtopic.php?t=4965 (while specific to printing, it can still be applied here as well)

Just replace wxWHITE_BRUSH with the proper system color and your set... though I'm willing to bet you'd then get picky about the menu item highlight color not showing through on transparent images.

Doing web design for years now, I understand your frustration (waiting on full alpha transparency support in IE has been hell, and will continue to be for years to come), but just remember your using a cross-platform GUI toolkit, and I'm sure the devs are more concerned about consistency across platforms than platform specific features. This is one area where you may need to just jump strait into Win32 API calls if your only platform in use is Windows XP. It's not like wxWidgets prevents you from doing it.

One last item that came to my attention. The 2.6.3 changelog shows this item as fixed: "wxImage::Copy() forgot the alpha channel" ... this could be a culprit as wxMenu could be using it for something. It may be worth downloading the 2.6.3-rc1 release or just checking out from CVS to see if that fixes it.
gekkehenkie
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jan 19, 2006 3:01 pm

Post by gekkehenkie »

Heh, "picky" is my second name :)

I'll check out cvs and see if it helps to get it fixed, otherwise I'll just ditch the whole menu image thing.
Post Reply