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?
simply draw wxImage semi transparent on screen
Re: simply draw wxImage semi transparent on screen
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.
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!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: simply draw wxImage semi transparent on screen
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:
thank you!
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;
Re: simply draw wxImage semi transparent on screen
Code: Select all
wxGraphicsContext *gc = wxGraphicsRenderer::GetDirect2DRenderer()->CreateContext(this);
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!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: simply draw wxImage semi transparent on screen
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?
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?
Re: simply draw wxImage semi transparent on screen
Then try with your current version first. Maybe the bugs that were fixed don't affect you.Hmmm, I had some problems with 3.1.1 recently, so that is not an option.
Yes, the mask is only 1-bit.EDIT: i guess that does not make sense, the mask has no colors, right?
Use the source, Luke!