0.VC(ui)-H前景色和背景色(单色图和彩色图转换)

在制作透明位图时,经常用到单色图(遮罩图,两色图)将他与目标位图进行"与""或"等操作就能得到想要的透明效果,在其中用到的最多的就是BitBlt这个函数,另外,在使用之前是要对目标位图进行前景和后景颜色的设置,为什么呢?请看MSDN的解说:

 

单色图与彩色图之间的转换

  模拟透明的方法也包含基于windows的单色图向彩色图转换的机制,反之亦然。Windows概念中的文本颜色(前景色)和背景色被用来映射两种格式的转换。在blt操作中,当dest为彩色图,src为单色图时,在进行ROP(SRCAND,SRCAND,SRCINVERT,SRCPAINT等),操作之前,单色图src中的0(black)像素被转换成dest的前景色,1(white)像素被转化为dest的背景色。相反,从彩色图向单色图转换时,即dest为单色图,src为彩色图时,src彩色图中所有与其背景颜色相同的像素变成1,与其背景不同的变为0。

  Transparency simulation can also involve the Windows-based mechanism for converting monochrome bitmaps to color bitmaps and vice versa. The Windows-based notion of a text (foreground) color and a background color is used to map between the two formats. During a blt operation with a color destination, a monochrome source bitmap (and/or a brush when applicable) is converted to color on the fly before the actual ROP is carried out on the bits. The 0 (black) pixels in the monochrome bitmap are converted to the destination's text (foreground) color, and the 1 (white) pixels are converted to the background color. Conversely, Windows converts a color source into monochrome when the destination is monochrome. In this situation, all pixels in the color bitmap that are the same color as the background color become 1s, and all the other pixels are converted to 0s. Because all of the examples below use monochrome masks, it is critical for an application to properly set the foreground and background colors (using SetTextColor and SetBkColor) before performing the blt operations.

你可能感兴趣的:(0.VC(ui)-H前景色和背景色(单色图和彩色图转换))