simply draw wxImage semi transparent on screen

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.
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

simply draw wxImage semi transparent on screen

Postby mael15 » Mon Sep 10, 2018 1:12 pm

I have multiple drawn (not loaded) images stored as wxImage. When I want to show them on screen, I convert them to wxBitmap and use wxDC::DrawBitmap. Works just fine, but now i want to show all but one image visually in the background. My ideal way would be to have the background images semi transparent and I found the wxImage::SetAlpha method, but it seems a little excessive to set the same alpha value to every pixel of every image.
Is there an easier way? I was hoping for something that keeps the wxImage data as it is and just copies it semi transparent onto the screen?

User avatar
doublemax
Moderator
Moderator
Posts: 12602
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: simply draw wxImage semi transparent on screen

Postby doublemax » Mon Sep 10, 2018 4:55 pm

Do you have images with transparent parts, or are they completely opaque and you just want to render the whole image blended over another image?

Except for changing the image data itself, the only way in the wxWidgets to do this would be through wxGraphicsContext::BeginLayer(opacity). I've never tried this though, so i'm not even sure that it does what i think it does.

https://docs.wxwidgets.org/trunk/classw ... caa097ca1f

Under MSW, you'll have to use the Direct2D renderer, that method is not implemented in the standard GDI+ renderer.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: simply draw wxImage semi transparent on screen

Postby mael15 » Fri Sep 14, 2018 7:27 am

i have images with a mask and the background color set to 100% transparent with the mask. i want to blend these over one another.
How do i change to the Direct2D renderer? the code will run exclusively under MSW.
I tried this without success:

Code: Select all

wxGraphicsContext *gc = wxGraphicsContext::Create(this);
gc->BeginLayer(0.5);
gc->DrawBitmap(*btmp, btmpPos.x, btmpPos.y, btmp->GetSize().GetWidth(), btmp->GetSize().GetHeight());
gc->EndLayer();
delete gc;

thank you!

User avatar
doublemax
Moderator
Moderator
Posts: 12602
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: simply draw wxImage semi transparent on screen

Postby doublemax » Fri Sep 14, 2018 8:54 am

Code: Select all

wxGraphicsContext *gc = wxGraphicsRenderer::GetDirect2DRenderer()->CreateContext(this);


It's used in the "drawing" sample.

You should use the latest wx version from GIT, the D2D renderer has seens quite a few bug fixes earlier this year.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: simply draw wxImage semi transparent on screen

Postby mael15 » Fri Sep 14, 2018 12:39 pm

Hmmm, I had some problems with 3.1.1 recently, so that is not an option.
Can I somehow change one colour on the mask to be semi transparent? Without redrawing the whole mask? That would work in my case.

EDIT: i guess that does not make sense, the mask has no colors, right?

User avatar
doublemax
Moderator
Moderator
Posts: 12602
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: simply draw wxImage semi transparent on screen

Postby doublemax » Fri Sep 14, 2018 1:05 pm

Hmmm, I had some problems with 3.1.1 recently, so that is not an option.
Then try with your current version first. Maybe the bugs that were fixed don't affect you.

EDIT: i guess that does not make sense, the mask has no colors, right?
Yes, the mask is only 1-bit.
Use the source, Luke!


Return to “C++ Development”

Who is online

Users browsing this forum: Google [Bot] and 8 guests