Please help me with alpha channel in HDC. I make HDC dc throw CreateCompatibleDC. Than call CreateDIBSection and can find bytes of image in memory. Than call DrawFrameControl to this dc. All works, but in memory there are 4 bytes per pixel and alpha channel fills by 00. Even if there were FF before. But I need alpha channel. How can I make DrawFrameControl set real alpha values or just don't touch them. Thank you. And sorry for bad english :(
You can't make GDI not write to the alpha / reserved byte of a four-byte-per-pixel bitmap. GDI is not really alpha-aware, with the exception of a couple of functions like AlphaBlend
. However, you can use the knowledge that it writes to and resets the alpha to 0 to know which pixels it wrote to, and manually fix the alpha afterwards.
For more information, read these three articles:
The first two probably give you enough information to achieve what you want.
These articles take a generic approach to handling alpha with GDI functions, by scanning for pixels where the alpha was clobbered and fixing it (and goes into more advanced techniques to draw several things on top of each other, with correct alpha.) FrameRect
draws a rectangle where the lines are one unit wide and high. You might find it more efficient to draw using lines, or even directly editing the pixel bitmap in memory, to draw straight lines in memory. That avoids having to scan the whole bitmap for GDI-drawn pixels - after all, since it's a rectangle with one-unit-wide-edges you know exactly which pixels will be drawn to already, and can edit them yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With