title: Does resizing jpeg images affect their compression?
body: <p>I'm resizing jpegs by using the Graphics.DrawImage method (see code fragment below). Can anyone confirm that this will not affect the compression of the new image?
  I have seen <a href="https://stackoverflow.com/questions/87753/resizing-an-image-without-losing-any-quality">this thread</a>, but I am talking specifically about compression of jpegs.</p>
  
  <pre><code>    private byte[] getResizedImage(String url, int newWidth)
      {
          Bitmap bmpOut = null;
          System.IO.MemoryStream outStream = new System.IO.MemoryStream();
  
          //input image is disposable
          using (Bitmap inputImage = LoadImageFromURL(url))
          {
              ImageFormat format = inputImage.RawFormat;
              decimal ratio;  //ratio old width:new width
              int newHeight = 0;
  
              //*** If the image is smaller than a thumbnail just return it
              if (inputImage.Width &lt; newWidth)
                  return null;
  
              ratio = (decimal)newWidth / inputImage.Width;
              decimal h = inputImage.Height * ratio;
              newHeight = (int)h;
  
              bmpOut = new Bitmap(newWidth, newHeight);
              Graphics g = Graphics.FromImage(bmpOut);
              g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
              // try testing with following options:
              //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
              //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
              //g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
              //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  
              g.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight);
              g.DrawImage(inputImage, 0, 0, newWidth, newHeight);
              bmpOut.Save(outStream, getImageFormat(url));
          }
  
          return outStream.ToArray();
  
      }
  </code></pre>