BitBlt参数详解[通俗易懂]

2022-11-02 16:43:23 浏览数 (2)

代码语言:javascript复制
对BitBlt()这个函数的最后一个参数的意义一直不是太了解,只会使用SRCCOPY ,最近的一个项目使用到了这个函数,但是要求要背景透明的将源绘制到目标区域上,源是背景色和字,怎么只拷贝字而把背景色透明化呢?? 
代码语言:javascript复制
我的解决方法是,把源的背景色绘制为白色,字为黑色,然后在BitBlt的时候最后一个参数用SRCAND,果然可以达到我要的效果,这是为什么呢?呵呵 趁此机会好好看看这个参数介绍吧~~ 
代码语言:javascript复制
开始之前,首先要明白,绘制其实就是在给每一个像素点涂颜色,每种颜色都是由红蓝黄三要素组合而成,因此通过RGB 颜色值可以指定出一种颜色,一个 RGB 颜色值由三个两位十六进制数字组成,分别代表各自的颜色强度。例如,颜色值 #FF0000(十六进制) 之所以被渲染为红色,是因为红色的值达到了最高值 FF (等于十进制的 255)。同时红色也可以通过RGB(255,0,0)来表示,也可以通过二进制的0X11111001来表示。
代码语言:javascript复制
BOOL BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,  
代码语言:javascript复制
 HDC hdcSrc, int nXSrc, int nYSrc, DWORD 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,在进行与操作之后目标区的相应部分也成了黑色~~!因此看前来像是,将源以背景透明的方式拷贝到了目标上~~!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/180513.html原文链接:https://javaforall.cn

0 人点赞