|
代码在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)

|