我有一些小的透明GIF图像(在100×100),并写了下面的代码在所有的像素迭代给我的RGB值:C#图形新手问题
private void IteratePixels(string filepath)
{
string dataFormat = String.Empty;
Bitmap objBitmap = new Bitmap(filepath);
int counter = 0;
for (int y = 0; y < objBitmap.Height; y++)
{
for (int x = 0; x < objBitmap.Width; x++)
{
Color col = objBitmap.GetPixel(x, y);
dataFormat = String.Format("{0} => Red: {1:x} Green: {2:x} Blue: {3:x}",
counter++, col.R, col.G, col.B);
System.Diagnostics.Debug.WriteLine(dataFormat);
// Perform an operation on the Color value here.
// objBitmap.SetPixel(x, y, col);
}
}
}
代码工作(尽管是缓慢的,因为的GetPixel和字符串格式),但我最惊讶的是,输出报告透明像素是黑色的!我想知道为什么?
0 =>红色:绿色0:0蓝:0
1 =>红色:绿色0:0蓝:0 ...
现在让我们假设,如果我也有一个透明的gif图像一个覆盖图像面积25%的黑色背景,我怎么知道像素是透明还是黑色?