MFC AlphaBlend 函数


The AlphaBlend function displays bitmaps that have transparent or semitransparent pixels.
【AlphaBlend函数显示拥有透明或半透明像素点的位图。】

Syntax(语法)

BOOL AlphaBlend(  
  HDC hdcDest,                 // handle to destination DC(目标DC的句柄)
  int nXOriginDest,            // x-coord of upper-left corner(目标起点左上角X坐标)
  int nYOriginDest,            // y-coord of upper-left corner(目标起点左上角Y坐标)
  int nWidthDest,              // destination width(目标宽)
  int nHeightDest,             // destination height(目标高)
  HDC hdcSrc,                  // handle to source DC(源DC的句柄)
  int nXOriginSrc,             // x-coord of upper-left corner(源起点左上角X坐标)
  int nYOriginSrc,             // y-coord of upper-left corner(源起点左上角Y坐标)
  int nWidthSrc,               // source width(源宽)
  int nHeightSrc,              // source height(源高)
  BLENDFUNCTION blendFunction  // alpha-blending function(α混合函数)
);

Parameter(参数)

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.
【以逻辑单位指定目标矩形左上角的x坐标。】
nYOriginDest[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
【以逻辑单位指定目标矩形左上角的y坐标。】
nWidthDest[in] Specifies the width, in logical units, of the destination rectangle.
【以逻辑单位指定目标矩形的宽度。】
nHeightDest[in] Specifies the height, in logical units, of the destination rectangle.
【以逻辑单位指定目标矩形的高度。】
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.
【以逻辑单位指定源矩形左上角的x坐标。】
nYOriginSrc[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
【以逻辑单位指定源矩形左上角的y坐标。 】
nWidthSrc[in] Specifies the width, in logical units, of the source rectangle.
【以逻辑单位指定目标矩形的宽度。】
nHeightSrc[in] Specifies the height, in logical units, of the source rectangle.
【以逻辑单位指定目标矩形的高度。】
blendFunction[in] 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.
【指定源位图和目标位图的alpha混合函数、应用于整个源位图的全局alpha值以及源位图的格式信息。】

The source and destination blend functions are currently limited to AC_SRC_OVER. See the BLENDFUNCTION and EMRALPHABLEND structures.
【源和目标混合函数当前限制为AC_SRC_OVER。请参见BLENDFUNCTIONEMRALPHABLEND结构。】

Return Values(返回值)

If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE.
Windows NT/2000/XP: To get extended error information, call GetLastError. This can return the following value.
【成功返回TRUE,失败返回FALSE。通过GetLastError获得更多的错误信息。错误值如下】

ValueMeaning
ERROR_INVALID_PARAMETER (宏值为87)One or more of the input parameters is invalid.

Remarks(备注)

If the source rectangle and destination rectangle are not the same size, 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 (that is, BLACKONWHITE, WHITEONBLACK, and HALFTONE are changed to COLORONCOLOR).
【如果源矩形和目标矩形的大小不同,则会拉伸源位图以匹配目标矩形。如果使用了SetStretchBltMode 函数,iStretchMode 的值自动被修改为COLORONCOLOR(BLACKONWHITE, WHITEONBLACK, 和HALFTONE被改为COLORONCOLOR)。】

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.
【通过使用当前为目标设备上下文指定的转换来转换目标坐标。通过使用当前为源设备上下文指定的转换来转换源坐标。】

An error occurs (and the function returns FALSE) if the source device context identifies an enhanced metafile device context.
【如果源设备上下文标识了一个增强的图元文件设备上下文,将触发错误(函数返回FALSE)。】

If destination and source bitmaps do not have the same color format, AlphaBlend converts the source bitmap to match the destination bitmap.
【如果目标位图和源位图的颜色格式不同,AlphaBlend将转换源位图以匹配目标位图。】

AlphaBlend does not support mirroring. If either the width or height of the source or destination is negative, this call will fail.
【AlphaBlend不支持镜像。如果源或目标的宽度或高度为负,则此调用将失败。】

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.
【渲染到打印机时,首先使用SHADEBLENDCAPS调用GetDeviceCaps,以确定打印机是否支持与AlphaBlend混合。注意,对于显示DC,支持所有混合操作,并且这些标志表示操作是否被加速。】

If the source and destination are the same surface, that is, they are both the screen or the same memory bitmapand the source and destination rectangles overlap, an error occurs and the function returns FALSE.
【如果源和目标是同一个曲面,即它们都是屏幕或同一内存位图,并且源和目标矩形重叠,则会发生错误,函数返回FALSE。】

The source rectangle must lie completely within the source surface, otherwise an error occurs and the function returns FALSE.
【源矩形必须完全位于源曲面内,否则会发生错误,函数将返回FALSE。】

AlphaBlend fails if the width or height of the source or destination is negative.
【如果源或目标的宽度或高度为负,AlphaBlend将失败。】

Note 【注意】
The SourceConstantaAlpha member of BLENDFUNCTION 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. Set the SourceConstantAlpha value to 255 (which indicates that the image is opaque) when you only want to use per-pixel alpha values.
BLENDFUNCTION的SourceConstantaAlpha成员指定要在整个源位图上使用的alpha透明度值。SourceConstantAlpha值与任何每像素alpha值组合。如果SourceConstantAlpha为0,则假定图像是透明的。如果只希望使用每像素alpha值,请将SourceConstantAlpha值设置为255(这表示图像不透明)。】

心得体会

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值