单色位图

位图中的颜色在文件中按位存储,我们平时所见位图多试24位或32位。24位位图的含义是图片上每个像素点由24bit存储,24位位图由RGB三种颜色组成,每种颜色占一字节也就是8位,32位位图比24位位图多了透明通道(alpha通道)。这里所说的单色位图就是每个像素点仅用1bit存储,其值只能是0或1,即黑色和白色。

常用位图数据复制函数BitBlt是将一块位图数据复制到另一块地址中,但是32位位图和单色位图之间复制会怎么样呢?

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.

http://msdn.microsoft.com/en-us/library/fcbk8779.aspx

从单色位图到彩色位图,单色位图中是1的地方需要先转换为彩色位图的背景色,全0的地方需要转换为前景色,然后在进行块间操作;从彩色位图到单色位图,彩色位图中所有和背景色一致的地方设置为全1,即白色,其余部分为0,黑色

http://blog.csdn.net/ThomasLiu83/article/details/443385

原文地址:https://www.cnblogs.com/aishangxue/p/3669595.html