关于VC简单的透明绘图 bitblt

vincent_1011 2009-08-01 02:14:01
掩码位图是怎么生成的呢?

网上的解释觉得那些人也是人云亦云。。。

//C、生成掩码位图。
SetBkColor(hDC, Tcol);// 设置透明色
BitBlt(mDC,0,0,nW0,nH0,hDC,0,0,SRCCOPY);// mdc是单色位图DC。生成白色透明区,其它区域为黑色的掩码位图


这是怎么原理呢。我理解是创建mDC的时候是单色位图选进去的。所以一selectObject之后,我把这个DC显示出来的时候

发现全是黑色的,我觉得这是因为创建的时候默认是0,而0就是黑色。

经过上面的copy之后,为什么就可以生成掩码图了呢??SetBkColor到底是做了什么呢?一张图片其实就没分什么背景不背景的

最多算是首先画而已,如果后面画出的东西盖住这个前景范围的话,那根本就没什么背景图了。背景图只是抽象出来的概念而已

不知道哪位可以解释下生成掩码原理。谢谢了
...全文
1251 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sandy_zc_1 2009-08-06
  • 打赏
  • 举报
回复
LZ你写的方法也太诡异了吧。

BitBlt进行透明色处理的基本原理是各种光栅化位运算,这些位运算对特定的颜色处理没有效果,这样就达到了滤色的目的。

至于生成掩码,有很多种方法,LZ貌似是采用SetBkColor和SetTextColor,这个东西在MSDN中说的很晦涩,仅仅提到在将彩色位图与单色位图转换的时候会用到这些设定值。
GDI的PlatformSDK里面都没有提到,只有新版MFC的帮助中有提到一点:
引用
When the BitBlt function converts a monochrome bitmap to color, it sets white bits (1) to the background color and black bits (0) to the foreground color. The foreground and background colors of the destination device context are used. To convert color to monochrome, BitBlt sets pixels that match the background color to white and sets all other pixels to black. BitBlt uses the foreground and background colors of the color device context to convert from color to monochrome.

也就是说当彩色位图BitBlt到单色位图上的时候,会将和背景色一样的颜色转换成白色而其它颜色转换成黑色。背景色通过SetBkColor在彩色位图上设定。

还有其它的设定透明色的方式,比如逐像素遍历位图,另外还有生成两幅彩色图片(一背景黑一背景白)来达到透明绘图的方法,总之很多。


不过用VC进行透明绘图没那么麻烦吧,直接一个TransparentBlt就搞定了么,速度快效果好。
dronly 2009-08-05
  • 打赏
  • 举报
回复
做个记号,学习了.
subo86 2009-08-05
  • 打赏
  • 举报
回复
When the BitBlt function converts a monochrome bitmap to color, it sets white bits (1) to the background color and black bits (0) to the foreground color. The foreground and background colors of the destination device context are used. To convert color to monochrome, BitBlt sets pixels that match the background color to white and sets all other pixels to black. BitBlt uses the foreground and background colors of the color device context to convert from color to monochrome.
...
MSDN 原话,具体怎样实现的,估计BitBlt的时候原图每个像素先比较一下背景色,像素值是背景色的对应掩码图像素设为(255,255,255),否则(0,0,0)。
lostemop 2009-08-04
  • 打赏
  • 举报
回复
我也想问这个问题,楼主问的好 setbkcolor()到底起到什么作用了,学程序我觉得不单单学个api,只有里面的原理清楚了,才能写出更好的代码~
sanguomi 2009-08-01
  • 打赏
  • 举报
回复
这些东西本身就只是个API而已, 微软又没给你提供代码,只是告诉你怎么使用
vincent_1011 2009-08-01
  • 打赏
  • 举报
回复
晕,那上边没说清楚啊,我想知道原理啊。

难道你只是记着在把imagedc复制到单色DC的时候,对imagedc设置背景色就行了吗?

这个我也知道啊。。。

问题是我要知道什么原理呢?明明是copy过去的,虽然那个是单色,但是setbkcolor是怎么影响这个copy操作的呢?

别再贴连接了,google上我都找过了,全是一笔带过:设置透明色,copy。OK

  • 打赏
  • 举报
回复
http://www.vscodes.com/soft/25/80/1163.html

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧