BitBlt詳解

對BitBlt()這個函數的最後一個參數的意義一直不是太瞭解,只會使用SRCCOPY ,最近的一個項目使用到了這個函數,但是要求要背景透明的將源繪製到目標區域上,源是背景色和字,怎麼只拷貝字而把背景色透明化呢??
我的解決方法是,把源的背景色繪製爲白色,字爲黑色,然後在BitBlt的時候最後一個參數用SRCAND,果然可以達到我要的效果,這是爲什麼呢?呵呵 趁此機會好好看看這個參數介紹吧~~
開始之前,首先要明白,繪製其實就是在給每一個像素點塗顏色,每種顏色都是由紅藍黃三要素組合而成,因此通過RGB 顏色值可以指定出一種顏色,一個 RGB 顏色值由三個兩位十六進制數字組成,分別代表各自的顏色強度。例如,顏色值 #FF0000(十六進制) 之所以被渲染爲紅色,是因爲紅色的值達到了最高值 FF (等於十進制的 255)。同時紅色也可以通過RGB(255,0,0)來表示,也可以通過二進制的0X11111001來表示。
BOOL BitBlt(HDC hdcDestint nXDestint nYDestint nWidthint nHeight,
HDC hdcSrcint nXSrcint nYSrcDWORD dwRop );

Parameters

hdcDest
[in] Handle to the destination device context.
目標設備HDC
nXDest
[in] Specifies the logical x-coordinate of the upper-left corner of the destination rectangle.
目標區域的左頂點在目標畫布上的X座標
nYDest
[in] Specifies the logical y-coordinate of the upper-left corner of the destination rectangle.
目標區域的左頂點在目標畫布上的Y座標
nWidth
[in] Specifies the logical width of the source and destination rectangles.
BitBlt操作區域的寬度
nHeight
[in] Specifies the logical height of the source and the destination rectangles.
BitBlt操作區域高度
hdcSrc
[in] Handle to the source device context.
源設備的HDC
nXSrc
[in] Specifies the logical x-coordinate of the upper-left corner of the source rectangle.
源區域左頂點在源畫布上的X座標
nYSrc
[in] Specifies the logical y-coordinate of the upper-left corner of the source rectangle.
源區域左頂點在源畫布上的Y座標
dwRop
[in] Specifies a raster-operation code. 光柵操作代碼(關鍵參數)

These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color.

The following list shows some common raster operation codes.

Value Description
BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette.

This color is black for the default physical palette.

使用物理調色板的0索引顏色填充目標區域

(物理調色板的默認0索引顏色是黑色

DSTINVERT

Inverts the destination rectangle.

將目標區域的各像素點顏色值進行取反操作

MERGECOPY

Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator.

將源區域與指定的筆刷進行合併,即進行“AND()”

MERGEPAINT

Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.

將源區域取反後與目標區域進行“ (OR)”操作

NOTSRCCOPY

Copies the inverted source rectangle to the destination.

將源區域色值取反後拷貝到目標區域

NOTSRCERASE

Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.

將源區域與目標區域按照“(OR)”操作進行混合,然後將結果顏色進行取反操作

PATCOPY

Copies the specified pattern into the destination bitmap.

將指定的筆刷拷貝到目標位圖上

PATINVERT

Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.

通過“異或(XOR)”操作,將指定的筆刷與目標區域的顏色進行混合

PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator.

The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.

SRCAND

Combines the colors of the source and destination rectangles by using the Boolean AND operator.

通過“按位與(AND)”操作混合源和目標區域。

SRCCOPY

Copies the source rectangle directly to the destination rectangle.

直接將源拷貝到目標區域

SRCERASE

Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.

將目標區域顏色進行取反之後通過“按位與(AND)”操作與源進行混合

SRCINVERT

Combines the colors of the source and destination rectangles by using the Boolean XOR operator.

通過“異或(XOR)”操作混合源和目標區域

SRCPAINT

Combines the colors of the source and destination rectangles by using the Boolean OR operator.

通過“按位(OR)”操作混合源和目標區域

WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette.

This color is white for the default physical palette.

使用物理調色板的1索引顏色填充目標區域

(物理調色板的默認1索引顏色是白色

For the complete list of raster operations codes, see Ternary Raster Operations.

Return Values

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

 

通 過上述介紹,想必大家知道爲什麼了吧,我的背景是白色,字是黑色,在進行SRCAND操作的時候,白色是#ffffff 所以進行bitblt之後的顏色以目標區域的顏色爲本,而因爲字是黑色#000000,在進行與操作之後目標區的相應部分也成了黑色~~!因此看前來像 是,將源以背景透明的方式拷貝到了目標上~~!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章