Alpha channel in DeviceContext (HDC)

拥有回忆 提交于 2019-12-05 08:14:12

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!