There are currently 3 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1194 2
【用法】AlphaBlend半透明函数的用法
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 7/7/16 23:12

BLENDFUNCTION bdf;
ZeroMemory(&bdf, sizeof(bdf));
bdf.SourceConstantAlpha = 150; // 指定不透明度(0为完全透明, 255为完全不透明)
SelectObject(hdcMem, hbmp); // 选入要复制的位图
AlphaBlend(hdc, 50, 50, bmp.bmWidth / 2, bmp.bmHeight / 2, hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, bdf);


运行效果:

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 7/7/16 23:17

各参数的解释:
AlphaBlend(目标设备DC, 显示位置x坐标, 显示位置y坐标, 显示宽度, 显示高度, 含有图像的DC, 开始截取位置x坐标, 开始截取位置y坐标, 截取宽度, 截取高度, 半透明属性);

合理调整显示宽度和高度可以缩放图像,例如bmp.bmWidth / 2, bmp.bmHeight / 2就是缩小为原尺寸的50%。

函数执行时先进行原图像剪切,未剪切的部分不会显示出来。

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 7/7/16 23:18
如果bdf.SourceConstantAlpha为255的话,此函数就相当于StretchBlt。
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1194 Replies: 2
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 7/7/16 23:18
Bar Good Posts
Announcements