BitBlt参数详解[通俗易懂]

BitBlt参数详解[通俗易懂]对BitBlt()这个函数的最后一个参数的意义一直不是太了解,只会使用SRCCOPY,最近的一个项目使用到了这个函数,但是要求要背景透明的将源绘制到目标区域上,源是背景色和字,怎么只拷贝字而把背景色透明化呢??我的解决方法是,把源的背景色绘制为白色,字为黑色,然后在BitBlt的时候最后一个参数用SRCAND,果然可以达到我要的效果,这是为什么呢?呵呵趁此机会好好看看这个参数介绍吧~~开始之前,首先要明白,绘制其实就是在给每一个像素点涂颜色,每种颜色都是由红蓝黄三要素组合而成,因此通过RGB颜色值可以


Jetbrains全系列IDE稳定放心使用

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

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • nv12转yuv420_百转

    nv12转yuv420_百转YU12格式也叫I420格式,是YUV420p其中的一种,NV12是YUV420sp的一种。YU12和NV21中YUV数据的排列方式为:YU12:YYYYYYYYUUVVNV12:YYYYYYYYUVUV针对数据排列顺序结构,本文将NV12转为YU12。主要转换接口实现为:intNV12toYU12(char*data,char*out,intwidth,intheight);具体代码如下:/************************************

    2022年9月24日
  • urlopen error errno111(英雄联盟报错error)

    原因获取地址信息失败,通常是由于自动选择的DNS服务器不行解决方法更换DNS服务器控制面板(win+R+control)->网络和Internet2.打开网络共享中心3.打开当前连接的网络,以wifi为例4.打开属性5.打开Internet协议版本46.选择使用特定DNS服务器地址,并设置为114.114.114.1148.设置完成后,错误解决…

    2022年4月18日
  • html嵌入python代码(python做人脸识别)

    最近闲来无事,研究研究在安卓上跑Python。想起以前玩过的kivy技术,kivy[1]是一个跨平台的UI框架。当然对我们最有用的是,kivy可以把python代码打包成安卓App。但是由于安卓打包的工具链很长,包括androidsdk打包java代码、ndk编译python、编译各种python依赖包,经常花一整天从入门到放弃。这次使出认真研究的心态,终于找到一个解决方案,于是有了这篇文章:…

    2022年4月16日
  • jconsole 连接 eclipse启动项

    jconsole 连接 eclipse启动项

    2022年1月4日
  • http请求报400报错

    http请求报400报错400是HTTP的状态码,主要有两种形式:1、badrequest意思是“错误的请求”;2、invalidhostname意思是“不存在的域名”。在ajax请求后台数据时有时会报HTTP400错误-请求无效(Badrequest);出现这个请求无效报错说明请求没有进入到后台服务里;1、确认发送的数据格式是否正确。调试查看你发送的数据格式是否正确或是否有乱码…

    2022年6月12日
  • double转BigDecimal精度丢失的解决方案。

    double转BigDecimal精度丢失的解决方案。因为double有精度丢失的问题,所以关于小数点的计算通常使用BigDecimal来计算。但直接调用BigDecimal的构造函数,会出现精度丢失问题。publicBigDecimal(doubleval){this(val,MathContext.UNLIMITED);}例子:publicclassDemo1{publicstaticvoidmain(String[]args){//输出结果:4.7999999999999998223

    2022年6月3日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号