Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This structure controls blending by specifying the blending functions for source and destination bitmaps.

Syntax

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.

BlendFlags

Must be zero.

SourceConstantAlpha

Specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlphavalue is combined with any per-pixel alpha values in the source bitmap. If you set SourceConstantAlphato 0, it is assumed that your image is transparent. When you only want to use per-pixel alpha values, set the SourceConstantAlphavalue to 255 (opaque) .

AlphaFormat

This member controls the way the source and destination bitmaps are interpreted. The following table shows the value for AlphaFormat.

Value Description

AC_SRC_ALPHA

This flag is set when the bitmap has an Alpha channel (that is, per-pixel alpha). Because this API uses premultiplied alpha, 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 before the call.

Remarks

When the AlphaFormatparameter is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail.

When the BlendOpparameter is AC_SRC_OVER , the source bitmap is placed over the destination bitmap based on the alpha values of the source pixels.

If the source bitmap has no per-pixel alpha value (that is, AC_SRC_ALPHA is not set), the SourceConstantAlphavalue determines the blend of the source and destination bitmaps, as shown in the following table. Note that SCA is used for SourceConstantAlphahere. Also, SCA is divided by 255 because it has a value that ranges from 0 to 255.

Copy Code
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.

Copy Code
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 by the following equations.

Copy Code
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.

Copy Code
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 SourceConstantAlphaand then the blend is based on the per-pixel alpha. The following equations show this. Note that SourceConstantAlphais divided by 255 because it has a value that ranges from 0 to 255.

Copy Code
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 

Requirements

Header windows.h
Windows Embedded CE Windows CE 5.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also