ich einige kleine transparente GIF-Bilder haben (unter 100x100) und schrieb den folgenden Code durch alle Pixel iterieren mir die RGB-Werte zu geben:C# Graphics Newbie Frage
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);
}
}
}
Der Code (wenn auch langsam funktioniert, weil GetPixel und die Formatierung der Strings), aber was mich am meisten überraschte war, dass die Ausgabe meldet, dass die transparenten Pixel schwarz sind! Ich wundere mich warum?
0 => Rot: 0 Grün: 0 Blue: 0
1 => Rot: 0 Grün: 0 Blue: 0 ...
Nun lassen Sie uns sagen, wenn ich tat ein transparentes GIF-Bild mit ein schwarzer Hintergrund, der 25% des Bildbereichs abdeckt, woher weiß ich, ob das Pixel transparent oder schwarz ist?