TransparentBlt实现

来源:互联网 发布:科比高中数据 编辑:程序博客网 时间:2024/06/05 08:16

参考:http://www.vckbase.com/document/viewdoc/?id=532

         http://www.mvps.org/user32/gditutorial.html

         以及MSDN2008中StrechBlt、SetBkColor和SetTextColor的Remarks部分。

         Updated@2010.12.25: Feng Yuan的GDI编程书的第10章Using DDBs的DDB Color Conversion

                                              小节有详细的介绍。。

 

这里我贴一下自己觉得从上面资料中找出的最重要的一些原理:

For a monochrome bitmap, the black area is really 0 bits and the white area is really 1 bits.

If StretchBlt must convert a monochrome bitmap to a color bitmap, it sets white
bits (1) to the background color and black bits (0) to the foreground color. To
convert a color bitmap to a monochrome bitmap, it sets pixels that match the
background color to white (1) and sets all other pixels to black (0). The
foreground and background colors of the device context with color are used.

Raster operations (SRCPAINT, SRCCOPY, etc) are performed only after any mapping
has taken place. They are performed bytewise on the image bytes. this is the most
efficient means of operation, but it means that logical raster operations performed
on 256 color displays will tend to have unexpected results, as any palettes are
totally ignored by this process. The default twenty system colors will behave in an
expected way, as the system palette has been arranged specially so the mappings
work. Instead of simply using the 1st twenty colors, the system palette uses the
first ten, and last ten colors, so when a NOT is performed on black (color index 0)
the result of the NOT operation (color index 255) is the expected white.

 

啥不说了,贴代码(里面有详细的注释):

 

附图一张(可以测试下,不让上传BMP图,转成gif了):

可以用上面的理论改写《Windows程序设计》第五版14章的BitMask例子,可以不用Rop 0x220326。。。