使黑色像素透明
问题描述:
我有两个图像,它们具有相同的大小。现在我需要删除图片1像素是黑色的BTMP使黑色像素透明
for (int c = 0; c < selFrame.Width; c++)
for (int j = 0; j < selFrame.Height; j++)
{
var pixel = selFrame.GetPixel(c, j);
var pixel2 = btmp.GetPixel(c, j);
if (pixel2.Equals(Color.Black) || pixel2.IsEmpty)
{
MessageBox.Show("qwe");
selFrame.SetPixel(c, j, Color.Transparent);
}
}
MessageBox中没有显示,那么这意味着它没有经过如果条件。
这里是BTMP
答
因为[255,0,0,0]确实不等于Color.Black
。
例如,黑色和FromArgb(0,0,0)不被认为是相等的,因为黑色是一个名为色和FromArgb(0,0,0)则不是。
按照在上述文件的建议,改变你的支票是:
if (pixel2.ToArgb() == Color.Black.ToArgb() || pixel2.IsEmpty)