Esempio n. 1
0
 public static WriteableBitmap MakeSmallerCopy(this WriteableBitmap original, int maxDimension)
 {
     var ratio = 0.0;
     if (original.PixelHeight > original.PixelWidth)
     {
         ratio = ((double)original.PixelHeight) / maxDimension;
     }
     else
     {
         ratio = ((double)original.PixelWidth) / maxDimension;
     }
     if (ratio > 1.0)
         ratio = 1.0;
     var newWidth = (int)Math.Floor(((double)original.PixelWidth) / ratio);
     var newHeight = (int)Math.Floor(((double)original.PixelHeight) / ratio);
     var toReturn = new WriteableBitmap(newWidth, newHeight);
     toReturn.Blit(toReturn.BoundingRect(), original, original.BoundingRect());
     return toReturn;
 }