title: image not scaled prior to cropping
body: <p>I have a method that will take a user uploaded file, scale proportionately and crop to a square. If the input image is not a square, the scaled image will be cropped from the center. In the code below, the saved output file is the desired 240x240 pixels, but the image is not being scaled prior to cropping and the crop is taking place at the 0,0 coordinates and not centered. See method below, scaling calculations removed and replaced with hard coded values for simplicity.</p>
  
  <pre><code>public static void ResizeAvatarImage(HttpPostedFileBase file)
  {
      Image sourceImage = Image.FromStream(file.InputStream);//input file size 660x960
  
      //**************************************************
      //Ommitting calculations here for scaling dimensions
      //**************************************************
  
      Bitmap bmPhoto = new Bitmap(240, 240);//desired output size
  
      using (var newImage = Graphics.FromImage(bmPhoto))
      {
          newImage.DrawImage(sourceImage, new Rectangle(0, 0, 240, 349),//proportionally scaled image size 
                                                        0, 54, 240, 240,//cropped image size with offset to center image in crop area
                                                        GraphicsUnit.Pixel);
      }
  
      bmPhoto.Save("C:\\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
  }
  </code></pre>