I've been trying to convert a bitmap object to a matrix of int. I drew the letter 'C' in paint on a blank white sheet and the program was supposed to initialize the arr in place (x,y) with '0' if the pixel in the Bitmap object in the same position (x,y) is white and correspondingly '1' if it were a black pixel.
I wrote the following code:
static void Main(string[] args)
{
Bitmap arie = new Bitmap(@"C:\Users\User\Desktop\letter.bmp");
object [,] arr = new object[arie.Width, arie.Height];
int min=1000,counter=1;
for (int i = 0; i < arr.GetLength(0) - 1; i++)
{
for (int j = 0; j < arr.GetLength(1) - 1; j++)
{
if (arie.GetPixel(i, j).ToArgb() == Color.White.ToArgb())
{
arr[i, j] = 0;
}
else
arr[i, j] = 1;
}
}
for (int i = 1; i < arr.GetLength(0) - 2; i++)
{
for (int j = 1; j < arr.GetLength(1) - 2; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
}
at the end the letter 'C' that I drew came out like this: http://teachers.web.cern.ch/teachers/archiv/hst2000/teaching/expt/wavesand/image39.gif
Can anyone seem to recognize the issue?