使黑色像素透明
Making black pixels transparent
我有两张图片,它们的大小相同。现在我需要删除图像 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 没有显示,这意味着它没有通过 If 条件。
这里是 btmp
因为 [255,0,0,0] 不 等于 Color.Black
。
For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.
根据上述文档中的建议,将支票更改为:
if (pixel2.ToArgb() == Color.Black.ToArgb() || pixel2.IsEmpty)
我有两张图片,它们的大小相同。现在我需要删除图像 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 没有显示,这意味着它没有通过 If 条件。
这里是 btmp
因为 [255,0,0,0] 不 等于 Color.Black
。
For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.
根据上述文档中的建议,将支票更改为:
if (pixel2.ToArgb() == Color.Black.ToArgb() || pixel2.IsEmpty)