BLENDFUNCTION
The BLENDFUNCTION structure controls blending by specifying the blending functions for source and destination bitmaps.【BLENDFUNCTION结构通过为源位图和目标位图指定混合函数来控制混合。】
typedef struct _BLENDFUNCTION {
BYTE BlendOp;
BYTE BlendFlags;
BYTE SourceConstantAlpha;
BYTE AlphaFormat;
}BLENDFUNCTION, *PBLENDFUNCTION, *LPBLENDFUNCTION;
Members(成员)
BlendOp
Specifies the source blend operation. Currently, the only source and destination blend operation that has been defined is AC_SRC_OVER. For details, see the following Remarks section. 【指定源混合操作。目前,唯一定义的源和目标混合操作是AC_SRC_OVER。有关详细信息,请参阅以下备注部分。】
BlendFlags
Must be zero. 【必须为零。】
SourceConstantAlpha
Specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values in the source bitmap. If you set SourceConstantAlpha to 0, it is assumed that your image is transparent. Set the SourceConstantAlpha value to 255 (opaque) when you only want to use per-pixel alpha values. 【指定要在整个源位图上使用的alpha透明度值。SourceConstantAlpha值与源位图中的任何每像素alpha值组合。如果将SourceConstantAlpha设置为0,则假定图像是透明的。如果只希望使用每像素alpha值,请将SourceConstantAlpha值设置为255(不透明)。
】
AlphaFormat
This member controls the way the source and destination bitmaps are interpreted. AlphaFormat has the following value. 【此成员控制源位图和目标位图的解释方式。AlphaFormat具有以下值。】
Value | Meaning |
---|---|
AC_SRC_ALPHA | This flag is set when the bitmap has an Alpha channel (that is, per-pixel alpha). Note that the APIs use premultiplied 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. 【当位图具有Alpha通道(即每像素Alpha)时,将设置此标志。注意,api使用预乘Alpha,这意味着位图中的红色、绿色和蓝色通道值必须与Alpha通道值预乘。例如,如果Alpha 通道值为x,则在调用之前,红色、绿色和蓝色通道必须乘以x并除以0xff。】 |
Remarks(备注)
When the AlphaFormat parameter is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail. 【当AlphaFormat参数为AC_SRC_ALPHA时,源位图必须为32位深度。否则,AlphaBlend函数将失败。】
When the BlendOp parameter is AC_SRC_OVER , the source bitmap is placed over the destination bitmap based on the alpha values of the source pixels. 【当BlendOp参数为AC_SRC_OVER 时,源位图将基于源像素的Alpha值放置在目标位图上。】
If the source bitmap has no per-pixel alpha value (that is, AC_SRC_ALPHA is not set), the SourceConstantAlpha value determines the blend of the source and destination bitmaps, as shown in the following table. Note that SCA is used for SourceConstantAlpha here. Also, SCA is divided by 255 because it has a value that ranges from 0 to 255.【如果源位图没有每像素alpha值(即未设置AC_SRC_ALPHA ),则SourceConstantAlpha值确定源位图和目标位图的混合,如下表所示。】
Dst.Red | = Src.Red * (SCA/255.0) | + Dst.Red * (1.0 - (SCA/255.0)) |
Dst.Green | = Src.Green * (SCA/255.0) | + Dst.Green * (1.0 - (SCA/255.0)) |
Dst.Blue | = Src.Blue * (SCA/255.0) | + Dst.Blue * (1.0 - (SCA/255.0)) |
If the destination bitmap has an alpha channel, then the blend is as follows.【如果目标位图有alpha通道,则混合如下。】
Dst.Alpha | = Src.Alpha * (SCA/255.0) | + Dst.Alpha * (1.0 - (SCA/255.0)) |
If the source bitmap does not use SourceConstantAlpha (that is, it equals 0xFF), the per-pixel alpha determines the blend of the source and destination bitmaps, as shown in the following table.【 如果源位图不使用SourceConstantAlpha(即,它等于0xFF),则每像素alpha将确定源位图和目标位图的混合,如下表所示。】
Dst.Red | = Src.Red | + (1 - Src.Alpha) * Dst.Red |
Dst.Green | = Src.Green | + (1 - Src.Alpha) * Dst.Green |
Dst.Blue | = Src.Blue | + (1 - Src.Alpha) * Dst.Blue |
If the destination bitmap has an alpha channel, then the blend is as follows.【如果目标位图有alpha通道,则混合如下。】
Dest.alpha | = Src.Alpha | + (1 - SrcAlpha) * Dst.Alpha |
If the source has both the SourceConstantAlpha (that is, it is not 0xFF) and per-pixel alpha, the source is pre-multiplied by the SourceConstantAlpha and then the blend is based on the per-pixel alpha. The following tables show this. Note that SourceConstantAlpha is divided by 255 because it has a value that ranges from 0 to 255【如果源具有SourceConstantAlpha(即,它不是0xFF)和每像素alpha,则源将被SourceConstantAlpha预乘,然后混合基于每像素alpha。下表显示了这一点。请注意,SourceConstantAlpha被255除,因为它的值在0到255之间】
Src.Red | = Src.Red | * SourceConstantAlpha / 255.0; |
Src.Green | = Src.Green | * SourceConstantAlpha / 255.0; |
Src.Blue | = Src.Blue | * SourceConstantAlpha / 255.0; |
Src.Alpha | = Src.Alpha | * SourceConstantAlpha / 255.0; |
Dst.Red | = Src.Red | + (1 - Src.Alpha) * Dst.Red |
Dst.Green | = Src.Green | + (1 - Src.Alpha) * Dst.Green |
Dst.Blue | = Src.Blue | + (1 - Src.Alpha) * Dst.Blue |
Dst.Alpha | = Src.Alpha | + (1 - Src.Alpha) * Dst.Alpha |