c# - 使用 C# 替换索引图像中的颜色

标签 c# graphics gdi+

我正在使用 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/

相关文章:

c# - 如何获取属性值

d3.js - Pixi.js vs Konva.js vs D3.js

visual-c++ - 如何获取光标下的像素颜色?

graphics - 循环分割蒙版中原始顶点的加权平均值

c++ - 从 IStream 加载 PNG 时 GDI+ 崩溃

c++ - 删除GDI+中某行的某一部分

c# - 在 JSON API 调用 (CrunchBase) 中循环遍历 List<Objects>

c# - Hive 和 HBase 集成 - 数据访问问题

c# - 当 InPlaceBitmapMetadataWriter.TrySave() 返回 false 时,如何向图像添加元数据?

Android使用Paint绘制两种不同颜色的虚线