我正在使用 Graphics.DrawImage 将索引位图写入另一个图像。索引图像中的黑色在写入“targetBitmap”时应替换为透明色
如何以高效的方式执行此操作?
var graphics = Graphics.FromImage(targetBitmap);
//I want the black color in "indexBitmap" to be transparent when it's written to "targetBitmap"
graphics.DrawImage(indexedBitmap,...)
最佳答案
创建颜色映射并将其作为“ImageAttributes”参数传递给 DrawImage 对我有用
var colorMaps = new[]{
new ColorMap {OldColor = Color.FromArgb(255, 0, 0, 0), NewColor = Color.Transparent}
};
var attr = new ImageAttributes();
attr.SetRemapTable(colorMaps);
关于c# - 使用 C# 替换索引图像中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5375438/