title: Using Bitmap to Convert Images from colour to black & white - Space Issue : c#
body: <p>I think this might be repeated but the code is not:
  I used the following code to convert images from jpg color to jpg b&amp;w.
  TH eproblem is that my color jpg is of size 500KB, but my converted b&amp;w jpg is 2.18MB, how to optimize the size of this conversion.</p>
  
  <pre><code>public void ConvertBlackAndWhiteImage()
        {
             System.Drawing.Bitmap originalImage = null;
             originalImage = new System.Drawing.Bitmap(@"C:\Users\anvesh.veerelli\Pictures\ash 3.jpg");
             System.Drawing.Color c;
  
             for (int i = 0; i &lt; originalImage.Width; i++)
             {
                  for (int j = 0; j &lt; originalImage.Height; j++)
                  {
                       c = originalImage.GetPixel(i, j);
                       int r = 0;
                       r = Convert.ToInt16(c.R);
                       int g = 0;
                       g = Convert.ToInt16(c.G);
                       int b = 0;
                       b = Convert.ToInt16(c.B);
                       int ans = (r + g + b) / 3;
                       if (ans &gt; 128)
                       {
                            r = 255;
                            g = 255;
                            b = 255;
                       }
                       else
                       {
                            r = 0;
                            g = 0;
                            b = 0;
                       }
                       c = System.Drawing.Color.FromArgb(r, g, b);
                       originalImage.SetPixel(i, j, c);
  
                  }
             }
             string tmpFileName = @"C:\Users\anvesh.veerelli\Pictures\Destination\test.jpg";
             originalImage.Save(tmpFileName, System.Drawing.Imaging.ImageFormat.Bmp);
        }
  </code></pre>