title: converting a grayscale image to black and white image in c#
body: <p>I have written some c# code converting my rgb image to grayscale and I would like to convert the grayscale to only 2 colors, black and while.
  Can you help?</p>
  
  <p><strong>Code:-</strong>  </p>
  
  <pre><code> Bitmap bmp = new Bitmap(file);
   int width = bmp.Width;
   int height = bmp.Height;
   int[] arr = new int[225];
   int i = 0;
   Color p;
  
   //Grayscale
   for (int y = 0; y &lt; height; y++)
   {
       for (int x = 0; x &lt; width; x++)
       {
           p = bmp.GetPixel(x,y);
           int a = p.A;
           int r = p.R;
           int g = p.G;
           int b = p.B;
           int avg = (r+g+b)/3;
           bmp.SetPixel(x, y, Color.FromArgb(a, avg ,avg, avg));
       }
   }
   pictureBox2.Image = bmp; 
  </code></pre>