Add transparency to images on wxBitmapButton 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
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Add transparency to images on wxBitmapButton

Post by extreme001 »

Hi.

I got a problem with wxBitmapButton. I'm working with PNG-Images on wxBitmapButton, The PNG-Images have transparency. If I load the png, there is no transparency.

Here is some code:

Code: Select all

else if (name == _T("icons/btn_cash_game_de.png"))
    {
        m_sPath = wxString::Format(_T("%s%s"),wxGetApp().PathStd.Get().GetDataDir(),_T("\\icons\\btn_cash_game_de.png"));
		wxBitmap bitmap(m_sPath, wxBITMAP_TYPE_PNG);
        return bitmap;
    }
That's the way i'm loading the images. After starting the app, the transparent area is not transparent.

Any ideas?

Thank you very much.
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Post by papillon68 »

Same problem here. IIRC in previous releases (2.6) it was working.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Grrr
Earned some good credits
Earned some good credits
Posts: 126
Joined: Fri Apr 11, 2008 8:48 am
Location: Netherlands

Post by Grrr »

I had some other problems with wxBitmapButton as well which were solved when I first create a wxImage, then a wxBitmap from this image.

Code: Select all

	wxImage image(imagePath);
	wxBitmap bitmap;
	if (image.IsOk())
		bitmap = wxBitmap(image);
At least transparent PNG images work this way (I haven't tried PNG images with Alpha channel). That is on Windows with wxWidgets 2.8.9.
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Post by papillon68 »

Even this way it doesn't work...
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Post by papillon68 »

I also tried using a mask: it does work, meaning the cut away unwanted parts of the image, but you can see the wxbitmapbutton background color anyway, so it is not made transparent.

Please anyone ?
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

papillon68 wrote:I also tried using a mask: it does work, meaning the cut away unwanted parts of the image, but you can see the wxbitmapbutton background color anyway, so it is not made transparent.

Please anyone ?
Not sure what you mean here; isn't it normal that you see the background of the bitmap button through transparent areas of the image?
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Post by papillon68 »

I was expecting that also the background part of the button would be made transparent.

Image that you have a panel with a background image.

I'd like to add a bitmapbutton with a circular shape, how would I do that ?
Use a png with as a background image for the button, right ?
But the problem is that, no matter what, the bitmapbutton always has a background color and therefore does not allow to see the panel background...
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

papillon68 wrote:I was expecting that also the background part of the button would be made transparent.

Image that you have a panel with a background image.

I'd like to add a bitmapbutton with a circular shape, how would I do that ?
Use a png with as a background image for the button, right ?
But the problem is that, no matter what, the bitmapbutton always has a background color and therefore does not allow to see the panel background...
Well yeah, if you want a clickable icon, with no button visible under, try passing flag wxNO_BORDER. Otherwise, just draw the icon on a small panel and catch mouse events on it.
Post Reply