title: .NET Saving jpeg with the same quality as it was loaded
body: <p>I have a cannon digital camera and I set it to take pictures with superfine quality and it outputs a .jpg file 3 mega in size.
  If I load it like this  in ASP.NET(this is useful to change it's dpi resolution or crop it or whaterver)</p>
  
  <pre><code>imgPicture = Image.FromFile(Config.WorkDirectory + this.TempPhotoName);
  bmpPicture = new Bitmap(imgPicture);
  </code></pre>
  
  <p>and then I save it again like this:</p>
  
  <pre><code>bmpModified.Save(Config.WorkDirectory + this.TempPhotoName,System.Drawing.Imaging.ImageFormat.Jpeg);
  </code></pre>
  
  <p>it outputs a jpg that is only 700KB or so in size. There is a loss of quality.</p>
  
  <p>I also tried saving it like this:</p>
  
  <pre><code>bmpPicture.Save(Config.WorkDirectory + this.TempPhotoName, codecJpeg, encparams);
  </code></pre>
  
  <p>where codecJpeg is</p>
  
  <pre><code>ImageCodecInfo codecJpeg = this.getEncoderInfo("image/jpeg");
  
  
      private ImageCodecInfo getEncoderInfo(string mimeType)
      {
          // Get image codecs for all image formats
          ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
  
          // Find the correct image codec
          for (int i = 0; i &lt; codecs.Length; i++)
              if (codecs[i].MimeType == mimeType)
                  return codecs[i];
          return null;
      }
  </code></pre>
  
  <p>and encparams:</p>
  
  <pre><code>EncoderParameters encparams = new EncoderParameters(1);
  encparams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 97L);
  </code></pre>
  
  <p>This way the size(and I suspect also the quality) is maintained but I am inputing the quality by hand.</p>
  
  <p>I want to ask:</p>
  
  <p>Is there a way to save the image with the same quality as it was loaded without hardcoding the quality value?</p>
  
  <p>Thank you in advance</p>