I am trying to write a C# program designed to convert a .bmp file into binary. The file is 16x16 pixels. Each black pixel represents a one in binary, so the number 10 would be █[]█[][][][][]
The problem I am having is that my code is not recognizing the black pixels, so the output is always zero.
public Bitmap imgToDecode;
private void button2_Click(object sender, EventArgs e)
{
int i = (imgToDecode.Height * imgToDecode.Width);
bool[] pixData = new bool[i];
int p = 0;
for (int k = 1; k < imgToDecode.Height; k++)
{
for (int m = 1; m < imgToDecode.Width; m++)
{
if (imgToDecode.GetPixel(m, k) == Color.Black)
{
pixData[p] = true;
}
else
{
pixData[p] = false;
}
p++;
}
}
for (int n = 0; n < pixData.Length; n++)
{
textBox2.Text = (textBox2.Text + (Convert.ToInt32(pixData[n])));
}
}
If anyone has an idea as to why the output is 0, could they please help me. Also any ways of improving the code would be welcomed.