如何使图片中某种特定的颜色透明??

myhex 2004-06-15 09:02:03
如何去掉一般图片的背景颜色?
就象绘制图标icon一样,边缘的颜色不会被显示出来,而形成一条丑陋的边。
...全文
443 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
l51 2004-06-24
  • 打赏
  • 举报
回复
哈哈,现炒现卖,我也刚找到^_^


强烈建议不使用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

9sun888 2004-06-19
  • 打赏
  • 举报
回复
如果你的imagelist中的一堆图片的背景色是一致的话,那么选取一张图片,采用函数getpixed(0,0)取图像左上角的颜色值,然后设置imagelist.transparentcolor属性为这个颜色值,运行时,图片是透明的,我已经试过了!
如果这一堆图片的背景色不一致,我想在运行时,如在Form_load中,将每个图片的image类别转化成bitmap类型后执行maketransparent()函数使其透明,然后再放入imagelist中,再设置imageindex的关联,这样就不会有边缘的颜色。当然像我宁愿去下载一个图标编辑器软件,将这些图片转化为透明的图标icon,在设计时就放入imagelist中,省得麻烦了!
lehehe 2004-06-17
  • 打赏
  • 举报
回复
通过使用函数getpixed()得到所要处理的颜色,然后使用maketransparent()函数,让他透明!这两个函数是bitmap类中的,可以将image类别转化成bitmap类型!
孟子E章 2004-06-16
  • 打赏
  • 举报
回复
http://www.codeproject.com/cs/media/CsTranspTutorial3.asp?df=100&forumid=36208&exp=0&select=799699
孟子E章 2004-06-16
  • 打赏
  • 举报
回复
http://www.c-sharpcorner.com/Code/2003/March/ThumbnailImages.asp
myhex 2004-06-16
  • 打赏
  • 举报
回复
没人理我!是因为这个很难吗?一定要加一句推者有分吗???
myhex 2004-06-16
  • 打赏
  • 举报
回复
楼上的哥们,你列的不是我所需的。我想要的是怎么使imagelist里的东西绘上去后,除掉边界上的颜色。imagelist.transparentcolor属性好象不管用。
另外好象imagelist 导进的gif动画图绘上去后就变成静止的了,怎么回事咧

17,741

社区成员

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

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