First of all, you can't store a Color
as an int
, which is why you should switch from int[][]
to Color[][]
.
To output your desired result, simply loop over the array again, formatting the result a bit using string.Format()
and some conditional operators.
for (int x = 0; x < maze.Width; x++)
for (int y = 0; y < maze.Height; y++)
Console.WriteLine(string.Format("{0}, {1}: {2}",
x, y,
colors[x][y].ToArgb() == Color.Black.ToArgb() ? "b" : (colors[x][y].ToArgb() == Color.White.ToArgb() ? "w" : "n")
));
Note that this code outputs n
if the pixel is neither black nor white.
Also note that you can omit the string.Format()
method aswell, since the Console.WriteLine()
function contains an overload with formatting possibility.
Edit:
If you want to define a color as white if their RGB color is greater than, for example 170, you could add up their RGB values (excluding alpha values here, since reading image data is mostly done without transparency) and check if their sum is greater than 170 * 3.
Color current = colors[x][y];
int rgbSum = current.R + current.G + current.B;
char whiteOrBlack = (170 * 3 < rgbSum) ? 'w' : 'b';
Console.WriteLine(string.Format("{0}, {1}: {2}", x, y, whiteOrBlack));
I just want to point out that 170 is a rather odd number to use here. Maybe it's more likely that you meant 128 (i.e. half a byte)?