AlphaBlend使用_编程资料

本文介绍AlphaBlend函数的应用,该函数用于显示具有透明或半透明像素的位图。文章详细解释了AlphaBlend函数的参数及其返回值,并提供了使用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值