且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一种制造图像的每个像素具有特定颜色的透明

更新时间:2023-11-09 13:44:34

一个很好的方法是使用 ImageAttributes 类设置的颜色列表来绘制重新映射时发生。这样做的好处是不错的表现,以及让您可以非常容易地改变重映射颜色。尝试像这样code ...

One good approach is to use the ImageAttributes class to setup a list of colors to remap when drawing takes place. The advantage of this is good performance as well as allowing you to alter the remapping colors very easily. Try something like this code...

ImageAttributes attribs = new ImageAttributes();
List<ColorMap> colorMaps = new List<ColorMap>();
//
// Remap black top be transparent
ColorMap remap = new ColorMap();
remap.OldColor = Color.Black;
remap.NewColor = Color.Transparent;
colorMaps.Add(remap);
//
// ...add additional remapping entries here...
//
attribs.SetRemapTable(colorMaps.ToArray(), ColorAdjustType.Bitmap);
context.Graphics.DrawImage(image, imageRect, 0, 0, 
                           imageRect.Width, imageRect.Height, 
                           GraphicsUnit.Pixel, attribs);