AlphaBlend使用_編程資料

AlphaBlend使用2008-01-24 15:39This function displays bitmaps that have transparent or semitransparent pixels.
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 to the destination device context.
nXOriginDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYOriginDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidthDest
[in] Specifies the width, in logical units, of the destination rectangle. This value cannot be negative.
nHeightDest
[in] Specifies the height, in logical units, of the destination rectangle. This value cannot be negative.
hdcSrc
[in] Handle to the source device context.
nXOriginSrc
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYOriginSrc
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidthSrc
[in] Specifies the width, in logical units, of the source rectangle. This value cannot be negative.
nHeightSrc
[in] Specifies the height, in logical units, of the source rectangle. This value cannot be negative.
blendFunction
[in] A BLENDFUNCTION structure that specifies the alpha-blending function for source and destination bitmaps, a global alpha value to be applied to the entire source bitmap, and format information for the source bitmap. The source and destination blend functions are currently limited to AC_SRC_OVER.
Return Values
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.
To get extended error information, call GetLastError. GetLastError can return the following value.
ValueDescription
ERROR_INVALID_PARAMETEROne or more of the input parameters is invalid.

Remarks
If the source rectangle and destination rectangle are different sizes, the source bitmap is stretched to match the destination rectangle. If the SetStretchBltMode function is used, the iStretchMode value is automatically converted to COLORONCOLOR for this function.
The destination coordinates are transformed by using the transformation currently specified for the destination device context. The source coordinates are transformed by using the transformation currently specified for the source device context.
If the source device context identifies an enhanced metafile device context, an error occurs (and the function returns FALSE).
If destination and source bitmaps do not have the same color format, AlphaBlend converts the source bitmap to match the destination bitmap.
AlphaBlend does not support mirroring. If either the width or height of the source or destination is negative, the call to AlphaBlend will fail.
When rendering to a printer, first call GetDeviceCaps with SHADEBLENDCAPS to determine if the printer supports blending with AlphaBlend. Note that, for a display DC, all blending operations are supported and these flags represent whether the operations are accelerated.
The source rectangle must lie completely within the source surface, otherwise an error occurs and the function returns FALSE.
The SourceConstantaAlpha member of the BLENDFUNCTION structure specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values. If SourceConstantAlpha is 0, it is assumed that the image is transparent. To use only per-pixel alpha values, set the SourceConstantAlpha value to 255 to indicate that the image is opaque.
Requirements
OS Versions: Microsoft® Windows CE® 5.0 and later.
Header: Windows.h.
Link Library: Coredll.lib.
在有些情況下需要加載 #pragma comment(lib,"Msimg32.lib")
CBitmap map1;
map1.LoadBitmap(IDB_BITMAP1);
CBitmap map2;
map2.LoadBitmap(IDB_BITMAP2);
CDC dc1;
dc1.CreateCompatibleDC(pDC);
dc1.SelectObject(map1);
CDC dc2;
dc2.CreateCompatibleDC(pDC);
dc2.SelectObject(map2);
pDC->BitBlt(0,0,50,50,&dc1,0,0,SRCCOPY);
BLENDFUNCTION pl;
pl.BlendOp=AC_SRC_OVER;
pl.BlendFlags=0;
pl.SourceConstantAlpha =175;
pl.AlphaFormat=0;
// pDC->BitBlt(0,0,50,50,&dc2,0,0,SRCCOPY);
::AlphaBlend(pDC->GetSafeHdc(),0,0,150,150,dc2.GetSafeHdc(),0,0,20,20,pl);

本文轉自
http://hi.baidu.com/csuhkx/blog/item/e7bd1bfad1d62e8d9e5146bd.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章