Alphablend-[daily APIs]

Source: Internet
Author: User
Tags sca

Alphablend 

 

This function Displays bitmaps with transparent or translucent pixels.

Syntax

Bool Alphablend (
HDC Hdcdest ,
Int Nxorigindest , Int Nyorigindest , Int Nwidthdest , Int Nheightdest ,
HDC Hdcsrc ,
Int Nxoriginsrc , Int Nyoriginsrc , Int Nwidthsrc , Int Nheightsrc ,
Blendfunction Blendfunction
);

Parameters

Hdcdest: [in] handle of the Target DC

Nxorigindest and nyorigindest: [in] X and Y coordinates in the upper left corner of the target rectangle.

Nwidthdest and nheightdest: [in] the width and height of the target rectangle. The value cannot be negative.

Hdcsrc: [in] source DC handle

Nxoriginsrc, nyoriginsrc: [in] X and Y coordinates in the upper left corner of the source rectangle, which are based on logical units.

Nwidthsrc and nheightsrc: [in] width and height of the source rectangle. The value cannot be negative.

Blendfunction: [in] specifies the Alpha hybrid function used for the source bitmap and the target bitmap, used for the global Alpha value and format information of the source bitmap. Currently, onlyAc_src_over.

Return Value 

If the call succeeds, true is returned. If the call fails, false is returned.

Get extended error information. Call getlasterror. getlasterror will return:Error_invalid_parameter, Indicates that one or more input parameters are incorrect.

Remarks 

If the source and target rectangles are of different sizes, the source bitmap is scaled to match the target rectangles. If you useSetstretchbltmodeFunction,IstretchmodeValue is automatically convertedColoroncolor.
The target coordinates are converted using the conversion method specified for the target device environment. The source coordinates are converted using the current conversion method specified for the Source Device environment.
If the source device environment is identified as an Enhanced Metafile device environment, an error occurs (and this function returns false ).
If the color format of the target and source bitmap is different, alphablend converts the source bitmap to match the target bitmap.
Alphablend does not support images. If the width or height of the source or target area is negative, the call will fail.
CallGetdevicecapsAnd inputShadeblendcapsThe parameter checks whether the printer supports alphablend mixing. Remember, for the displayed DC, all mixed operations are supported and these flags indicate whether the Operation Supports acceleration.
The source rectangle must be inside the source surface (that is, the source rectangle range cannot exceed the source bitmap range). Otherwise, an error occurs and the function returns false.
 BlendfunctionStructureSourceconstantaalphaThe Member specifies the Alpha transparency value on the source bitmap. The sourceconstantalpha value is combined with the Alpha value of each pixel. If sourceconstantalpha is 0, the image is completely transparent; If sourceconstantalpha is 255, the image is not transparent.

Requirements 

Header: Windows. h

Library: coredll. Lib

Windows Mobile: Windows Mobile version 5.0 and later

 

Blendfunction

 

This structure control specifies the hybrid function used for source bitmap and target bitmap. 

Syntax

Typedef struct _ blendfunction {

ByteBlendop;

ByteBlendflags;

ByteSourceconstantalpha;

ByteAlphaformat;

} Blendfunction, * pblendfunction, * lpblendfunction;

 

Members:

Blendop: Specifies the source hybrid operation. Currently, the unique mixed source and target operations are defined as ac_src_over. For more information, see the remarks section below.

Blendflags: The value must be 0.

Sourceconstantalpha: Specify the Alpha transparency value used for the entire source bitmap. The sourceconstantalpha value is combined with the Alpha value of each pixel. If sourceconstantalpha is 0, the image is completely transparent; If sourceconstantalpha is 255, the image is not transparent.

Alphaformat: This member controls how source and target bitmap are interpreted. The alphaformat value is shown below:

Ac_src_alphaThis indicates an alpha channel (each pixel has an Alpha value ). Because this API uses pre-multiplication α, the red, green, and blue channel values in the figure must be pre-multiplied by alpha channel values. For example, if the alpha channel value is X, it must be red, green, and blue before calling. The channel must be multiplied by X and then divided by 0xff.

Remarks

When the alphaformat parameter isAc_src_alphaThe source bitmap must be 32 colors. If not, the alphablend function fails.

When the blendop parameter isAc_src_overThe source bitmap is placed on the target map based on the Alpha value of the source pixel.

If ac_src_alpha is not set for the source bitmap, both the source and target bitmaps are determined by the sourceconstantalpha value, as shown in the following table. Note that the value of sourceconstantalpha is SCA. In addition, SCA is divided by 255 because its value range is 0 to 255.

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 target bitmap has an alpha channel, it is mixed as follows.

  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 is equal to 0xff), the Alpha value of each pixel determines the mixture of the source and target bitmaps, as shown in the following formula.

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 alpha channel of the target bitmap is the same as follows.
 DST .Alpha =SRC .Alpha + (1-SRC. Alpha )*DST .Alpha

If both the source bitmap sourceconstantalpha (that is, it is not 0xff) and each pixel has an Alpha value, the source bitmap is premultiplied by sourceconstantalpha and then mixed Based on the Alpha value of each pixel. See the following equation. Note that sourceconstantalpha is divided by 255 because its value ranges from 0 to 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

 

Requirements 

OS versions: Windows CE 5.0 and later.

Header: imaging. h.

 

Reference:

Msdn: alphablend blendfunction

Interactive Encyclopedia: alphablend

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.