12.VC(ui)-AlphaBlend参数BLENDFUNCTION

来源:互联网 发布:java 访问hadoop hdfs 编辑:程序博客网 时间:2024/05/01 19:57

AlphaBlend是Window自带的GDI函数,在作GUI的时候为了达到更漂亮的效果我们常常用它.

BLENDFUNCTION是AlphaBlend用控制透明效果的重要参数.

定义如下:

typedef struct _BLENDFUNCTION {  BYTE     BlendOp;  BYTE     BlendFlags;  BYTE     SourceConstantAlpha;  BYTE     AlphaFormat;}BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;

BlendOp: 这个参数必须也只能为AC_SRC_OVER(0x00),意思就是把源图片覆盖到目标之上.

BlendFlags: 必须为0

SourceConstantAlpha: 简写为SCA,指定源图片的透明度,这个值是会和源图片的Alpha通道值合并计算的.

AlphaFormat: 可以填两种,一种是0x00,一种是AC_SRC_ALPHA(0x01).填0的话,AlphaBlend据说就和BitBlt一样了,我没有试验过~填1的话,源DC必须是32位的DC不然的话,AlphaBlend会返回参数错误.

计算公式(当SCA不是0xFF时):

      输出像素(R,G,B,A) = 源像素(R,G,B,A) * SCA / 0xFF + 目标像素(R,G,B,A) * (1.0 - SCA / 0xFF)

当SCA是0xFF时,计算公式

      输出像素(R,G,B,A) = 源像素(R,G,B,A) + 目标像素(R,G,B,A) * (1.0 - 源像素(A) / 0xFF)

混合计算公式

       输出像素(R,G,B) = 源像素(R,G,B) * SCA / 0xFF + 目标像素(R,G,B) * (1.0 - 源像素(A) / 0xFF * SCA / 0xFF)


全部是PBGRA预乘方式:

ValueMeaningAC_SRC_ALPHAThis flag is set when the bitmap has an Alpha channel (that is, per-pixel alpha). Note that the APIs usepremultiplied alpha, which means that the red, green and blue channel values in the bitmap must be premultiplied with the alpha channel value. For example, if the alpha channel value is x, the red, green and blue channels must be multiplied by x and divided by 0xff prior to the call.

原创粉丝点击