Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AlphaBlend() and FillRect()

Tags:

c++

winapi

gdi

So, I'm using AlphaBlend() to copy a rectangle from one HBITMAP to another.

It works, but there is a problem. Whenever I use the FillRect() function, the alpha values in the HBITMAP get slammed out to 0. Everytime.

So I have to GetDIBits(), reset the alpha back to 255, and then SetDIBits(), after every call to the Win32 api functions like FillRect().

So, is there a way to create an HBRUSH or otherwise tell FillRect() not to touch the alpha channel values in the HBITMAP it is going to be drawing to?

like image 825
bobobobo Avatar asked Oct 16 '25 20:10

bobobobo


1 Answers

With the exception of AlphaBlend... BitBlt is the only other GDI function that will preserve the alpha channel in any way.

Your options basically therefore are:

  1. Switch to using DIBSections. This will not solve the basic problem of GDI apis overwiting the alpha channel, but as a DIBSection you can avoid the costly DDB -> DIB -> DDB transformation needed to patch up the alpha channel. DIBSections give you access to both an HBITMAP and a memory section where the bitmaps bits are stored.

  2. Use an alpha aware painting API like GdiPlus instead of GDI.

like image 69
Chris Becke Avatar answered Oct 18 '25 11:10

Chris Becke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!