title: How to Copy and Resize Image in Windows 10 UWP
body: <p>I have used the code from <a href="http://www.codeproject.com/Tips/552141/Csharp-Image-resize-convert-and-save" rel="noreferrer">http://www.codeproject.com/Tips/552141/Csharp-Image-resize-convert-and-save</a> to resize images programmatically. However, that project uses the <code>System.Drawing</code> libraries, which are not available to Windows 10 applications.</p>
  
  <p>I have tried using the <code>BitmapImage</code> class from <code>Windows.UI.Xaml.Media.Imaging</code> instead, but it does not seem to offer the functionality that was found in <code>System.Drawing</code>..</p>
  
  <p>Has anyone had any luck being able to resize (scale down) images in Windows 10? My application will be processing images from multiple sources, in different formats/sizes, and I am trying to resize the actual images to save space, rather than just letting the application size it to fit the <code>Image</code> in which it is being displayed.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have modified the code from the above mentioned link, and have a hack which works for my specific need. Here it is:</p>
  
  <pre><code>public static BitmapImage ResizedImage(BitmapImage sourceImage, int maxWidth, int maxHeight)
  {
      var origHeight = sourceImage.PixelHeight;
      var origWidth = sourceImage.PixelWidth;
      var ratioX = maxWidth/(float) origWidth;
      var ratioY = maxHeight/(float) origHeight;
      var ratio = Math.Min(ratioX, ratioY);
      var newHeight = (int) (origHeight * ratio);
      var newWidth = (int) (origWidth * ratio);
  
      sourceImage.DecodePixelWidth = newWidth;
      sourceImage.DecodePixelHeight = newHeight;
  
      return sourceImage;
  }
  </code></pre>
  
  <p>This way seems to work, but ideally rather than modifying the original <code>BitmapImage</code>, I would like to create a new/copy of it to modify and return instead.</p>
  
  <p>Here is a shot of it in action:
  <a href="https://i.stack.imgur.com/FFgeV.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/FFgeV.jpg" alt="screenshot of resized image"></a></p>