Clear or erase wxBitmap 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
bluesnowball18
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Apr 22, 2021 9:23 am

Clear or erase wxBitmap

Post by bluesnowball18 » Tue Apr 27, 2021 10:59 am

Is there an easy way to fill a rectangular area of wxBitmap or entire bitmap with transparent color?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Clear or erase wxBitmap

Post by ONEEYEMAN » Tue Apr 27, 2021 12:07 pm

Hi,
Convert it to image, set the transparency/alpha, then convert back.

How big is the bitmap?

Thank you.

bluesnowball18
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Apr 22, 2021 9:23 am

Re: Clear or erase wxBitmap

Post by bluesnowball18 » Tue Apr 27, 2021 2:43 pm

It can have any size up to 4096*4096 pixels.

User avatar
[email protected]
Experienced Solver
Experienced Solver
Posts: 97
Joined: Wed Jul 29, 2020 6:06 pm

Re: Clear or erase wxBitmap

Post by [email protected] » Tue Apr 27, 2021 3:11 pm

How time critical is the operation and how often do you have to do it?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Clear or erase wxBitmap

Post by ONEEYEMAN » Tue Apr 27, 2021 3:36 pm

Hi,
Are you targetting Windows only or you want it cross-platform?

Thank you.

bluesnowball18
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Apr 22, 2021 9:23 am

Re: Clear or erase wxBitmap

Post by bluesnowball18 » Tue Apr 27, 2021 10:22 pm

I think I've found a solution. Thank you for the responses.

Code: Select all

wxImage image("image.jpeg");
image.InitAlpha();

this->bitmap = wxBitmap(image);

Code: Select all

wxMemoryDC dc(this->bitmap);

dc.SetLogicalFunction(wxCLEAR);
dc.DrawRectangle(100, 100, 40, 20);

Post Reply