I have some code lines. I just want to convert a gray-scale image to a binary image. It look so simple but i don't understand where is wrong! Can you tell me where is it wrong. Here is it:
private void convert()
{
try
{
OpenFileDialog op = new OpenFileDialog();
op.InitialDirectory = "D:/";
op.Filter = "All Files|*.*|JPEGs|*.jpg|Bitmaps|*.bmp|GIFs|*.gif";
op.FilterIndex = 1;
if (op.ShowDialog() == DialogResult.OK)
{
pictureBox3.Image = Image.FromFile(op.FileName);
pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox3.BorderStyle = BorderStyle.Fixed3D;
Bitmap img = new Bitmap(op.FileName);
int width = img.Width;
int height = img.Height;
string t = "";
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
if (img.GetPixel(j, i).A > 100 && img.GetPixel(j, i).B > 100 && img.GetPixel(j, i).G > 100 && img.GetPixel(j, i).R > 100)
{
t = t + "0";
}
else
{
t = t + "1";
}
}
t = t + "\r\n";
}
textBox1.Text = t;
}
}
catch { };
}
Thanks all!