HDC中的前景色与背景色

HDC中的前景色与背景色

    

在制作透明位图时,经常用到单色图(遮罩图,两色图)将他与目标位图进行"与""或"等操作就能得到想要的透明效果,在其中用到的最多的就是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.

转载于:https://www.cnblogs.com/hgy413/archive/2011/06/24/3693632.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值