用GDI+ Gdiplus 怎样使图片的某种颜色透明显示

Fanjj 2004-03-12 04:55:19
各位高人:
我在用Gdiplus的DrawImage以某种颜色透明显示图片时,
不知道怎样设置 ImageAttributes,请各位不吝赐教。

Status DrawImage(IN Image* image,
IN const Rect& destRect,
IN INT srcx,
IN INT srcy,
IN INT srcwidth,
IN INT srcheight,
IN Unit srcUnit,
IN const ImageAttributes* imageAttributes = NULL,
IN DrawImageAbort callback = NULL,
IN VOID* callbackData = NULL)
...全文
255 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fanjj 2004-03-23
  • 打赏
  • 举报
回复
结贴。
Muf 2004-03-16
  • 打赏
  • 举报
回复
强烈建议不使用ImageAttributes,奇慢无比。
可以加工图片,使其自带Alpha通道,以达到透明的效果,速度还非常快。

如果非要用ImageAttributes,参考下例:

VOID Example_SetColorKey(HDC hdc)
{
Graphics graphics(hdc);

// Create an Image object based on a BMP file.
// The image has three horizontal stripes.
// The color of the top stripe has RGB components (90, 90, 20).
// The color of the middle stripe has RGB components (150, 150, 150).
// The color of the bottom stripe has RGB components (130, 130, 40).
Image image(L"ColorKeyTest.bmp");

// Create an ImageAttributes object, and set its color key.
ImageAttributes imAtt;
// 如果只有一种颜色,可以设置两个完全相同的颜色作为范围
imAtt.SetColorKey(
Color(100, 95, 30),
Color(250, 245, 60),
ColorAdjustTypeBitmap);

// Draw the image. Apply the color key.
// The bottom stripe of the image will be transparent because
// 100 <= 130 <= 250 and
// 95 <= 130 <= 245 and
// 30 <= 40 <= 60.
graphics.DrawImage(
&image,
Rect(20, 20, image.GetWidth(), image.GetHeight()), // dest rect
0, 0, image.GetWidth(), image.GetHeight(), // source rect
UnitPixel,
&imAtt);
}

-----------------------------
本例子来自 MSDN Library : Graphics and Multimedia / GDI+ / GDI+ Reference / Classed / ImageAttributes / ImageAttributes Methods / SetColorKey
netcoder 2004-03-16
  • 打赏
  • 举报
回复
不会,帮你顶

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧