C#的简单图片透明处理
代码在WinXP和WinCE5.0都可以使用。作用是2幅图叠加的时候,背景图不变,前景图指定颜色做透明处理。
使用到的是SetColorKey来设置透明色。
Graphics g = this.CreateGraphics();
Bitmap bitmap = new Bitmap(@"E:/xxx/testb.png");
Bitmap bmp = new Bitmap(@"E:/xxx/mouse.png");
imageAttr = new ImageAttributes();
imageAttr.SetColorKey(bmp.GetPixel(20, 20), bmp.GetPixel(20, 20));
g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
g.DrawImage(bmp, //叠加图
new Rectangle(5, 8, bmp.Width, bmp.Height), //要叠加到背景图的位置,尺寸
0, 0, bmp.Width, bmp.Height, //要叠加的尺寸
GraphicsUnit.Pixel, imageAttr); //透明阀值
// Dispose
g.Dispose();
背景图
要叠加的图

实际运行效果(WinXP)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
