I'm trying create a image png with transparency. Very basic...
But.. in the example bellow, i created a wxPanel black, and over it there are a image PNG with transparency. In true, part white in the image is a
PNG transparent, it's no white... I don't understand what is wrong. It's so basic.... Coul'd someone give one tip, please?
Panel_box = new wxPanel(newPanel, wxID_ANY,wxPoint(0,50),wxSize(200,100));
Panel_box->SetBackgroundColour(wxColor(0,0,0));
wxBitmap bmp;
bmp.LoadFile("image.png", wxBITMAP_TYPE_PNG);
ball = new wxButton(Panel_box, ID_ball, wxEmptyString, wxPoint(50,05), bmp.GetSize(), wxTRANSPARENT_WINDOW | wxBORDER_NONE);
ball->SetBitmap(bmp);
Transparency PNG Topic is solved
-
- Super wx Problem Solver
- Posts: 466
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Transparency PNG
When the "transparent" parts of an image are drawn, what really happens is that the background color of the window is drawn instead. ball thinks its background color is white so that's what gets drawn for the transparent parts of the image. You can try
to make the button think it has the same background color as the panel. That works on windows, but it may not work on GTK+ or mac since setting colors for buttons may not be supported on those platforms.
Code: Select all
ball->SetBackgroundColour(wxColor(0,0,0));
-
- Experienced Solver
- Posts: 56
- Joined: Sun May 05, 2019 7:12 am
Re: Transparency PNG
One more time, big big thanks, New Pagodi!!!!
Re: Transparency PNG
New Pagodi,
So it is best to modify the PNG and give it an appropriate background colour in order to make it cross-platform?
Thank you.
So it is best to modify the PNG and give it an appropriate background colour in order to make it cross-platform?
Thank you.
-
- Super wx Problem Solver
- Posts: 466
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Transparency PNG
That will work if the background color of the panel never changes. The only solution that is guaranteed to work on all ports is to skip the button class altogether, draw the bitmap directly on to the panel, and handle the mouse left up event on the panel and check if it is over the bitmap. But that's complicated enough that if setting the background color works for what OP wants, it might as well be done that way.
Re: Transparency PNG
New Pagodi,
Well for my use case I need the button on the toolbar, not the panel.
So I will just modify the PNG background and everybody will be happy.
Thank you.
Well for my use case I need the button on the toolbar, not the panel.
So I will just modify the PNG background and everybody will be happy.
Thank you.