單色位圖、顏色(色彩)位圖相互轉換


SetBkColor

The SetBkColor function sets the current background color to the specified color value, or to the nearest physical color if the device cannot represent the specified color value.

COLORREF SetBkColor(
  HDC hdc,           // handle to DC
  COLORREF crColor   // background color value
);

Remarks

If the background mode is OPAQUE, the background color is used to fill gaps between styled lines, gaps between hatched lines in brushes, and character cells. The background color is also used when converting bitmaps from color to monochrome and vice versa. 

 

SetTextColor

The SetTextColor function sets the text color for the specified device context to the specified color.

COLORREF SetTextColor(
  HDC hdc,           // handle to DC
  COLORREF crColor   // text color
);

 

Remarks

The text color is also used in converting bitmaps from color to monochrome and vice versa.

 

在MSDN中,以上兩個函數(一個是設置背景色,一個是設置前景色)的Remarks下均有說到設置的顏色,在單色位圖轉色彩位圖中會被用到,反之易然。

但是沒有具體說明具體的轉換原理,我也查找了很久,在官方文檔上也沒搜索到相關的說明,以下是來自網絡朋友的總結,感覺總結的很好,特此引用過來。

 

以下內容全部來自:http://www.programgo.com/article/20281711249/

 

當目標dc的位圖是顏色位圖,源dc的位圖是單色的時候,單色位圖在實際的光柵操作(ROP)之前會被轉換成顏色位圖,對應的位如果是0,則被轉換目標dc的前景色,如果該位是1,則被轉換成目標dc的背景色。相反,如果目標dc的位圖是單色位圖,源dc的位圖是顏色位圖,則在實際光柵操作之前要把顏色位圖轉換成單色位圖,轉換規則是,顏色位圖中所有和背景色一致的象素都變成1,其他的象素都被轉換成0。

 

以上這些是本人自己的觀察,理解和總結,至今還沒有查到官方的描述。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM