Good Day,
I have some small transparent gif images (under 100x100) and wrote the following code to iterate through all the pixels to give me the RGB values:
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);
}
}
}
The code works (albeit slow because of the GetPixel and the string formatting) but what I was most surprised at was that the output is reporting that the transparent pixels are black! I wonder why?
0 => Red: 0 Green: 0 Blue: 0
1 => Red: 0 Green: 0 Blue: 0
...
Now let's say if I did have a transparent gif image with a black background covering 25% of the image's area, how would I know whether the pixel is tranparent or black?
TIA,
coson