Alpha Channel in DeviceContext (HDC)

Please help me with the alpha channel in HDC. I am doing an HDC dc throw CreateCompatibleDC. Then call CreateDIBSection and you can find the image bytes in memory. Then call DrawFrameControl for this DC. Everything works, but in memory there are 4 bytes per pixel, and the alpha channel is filled at 00. Even if there used to be FF. But I need an alpha channel. How can I make DrawFrameControl set to real alpha values ​​or just not touch them. Thanks. And sorry for the bad English :(

+6
source share
1 answer

You cannot force GDI to not write to the alpha / reserved byte of a four-byte bitmap. GDI does not actually support the alpha version, except for a few features like AlphaBlend . However, you can use the knowledge that he writes and resets the alpha value to 0, to know which pixels he wrote on, and manually correct the alpha afterwards.

Read the following three articles for more information:

The first two probably give you enough information to achieve what you want.

These articles use a general approach to processing GDI alpha functions by scanning pixels in which alpha has been knocked down and fixed (and goes into more sophisticated methods to draw several things on top of each other, with the correct alpha). FrameRect draws a rectangle where the lines have a single width and height. You might find more efficient drawing using lines, or even directly editing a bitmap in memory to draw straight lines in memory. This avoids scanning the entire bitmap for the selected GDI pixels. In the end, since it is a rectangle with crop edges with one node, you know exactly which pixels are already drawn, and you can edit them yourself.

+7
source

Source: https://habr.com/ru/post/913010/


All Articles