title: Reducing JPEG image quality without saving
body: <p>I am trying to programatically reduce the quality of an image in the fastest way possible. Right now, I am able to read image from <code>byte[]</code>, then as a <code>MemoryStream</code> read it to <code>Bitmap</code> and via <code>Drawing.Imaging.Encoder.Quality</code> change its quality when saving to desired <code>20L</code>.</p>
  
  <p>I would like to know if there is a way to do this without saving the whole image. Is there way to just change the bitmap <code>bmp1</code>, or create a new bitmap that would have the image quality reduced? </p>
  
  <pre><code>byte[] imageBytes = convertImageToByteArray(bmpScreenshot);
  MemoryStream mem = new MemoryStream(imageBytes);
  using (Bitmap bmp1 = (Bitmap)Image.FromStream(mem))
  {
  
       ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
       ImageCodecInfo jgpEncoder = codecs[1];
  
       System.Drawing.Imaging.Encoder myEncoder =
       System.Drawing.Imaging.Encoder.Quality;
  
       myEncoderParameter = new EncoderParameter(myEncoder, 20L);
       myEncoderParameters.Param[0] = myEncoderParameter;
       bmp1.Save(@"C:\TestPhotoQuality20L.jpg", jgpEncoder, myEncoderParameters);
  }
  </code></pre>