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.
source share