Esempio n. 1
0
 public static Size Confine(Size requiredSize, Size imageSize)
 {
     if (imageSize.Width <= requiredSize.Width && imageSize.Height <= requiredSize.Height)
     {
         return imageSize;
     }
     var scaleW = requiredSize.Width / (double)imageSize.Width;
     var scaleH = requiredSize.Height / (double)imageSize.Height;
     var scale = Math.Min(scaleW, scaleH);
     return new Size
     {
         Width = (int)Math.Round((imageSize.Width * scale)),
         Height = (int)Math.Round((imageSize.Height * scale))
     };
 }
Esempio n. 2
0
 public static Size Confine(int boundingSquare, Size imageSize)
 {
     return Confine(new Size { Width = boundingSquare, Height = boundingSquare }, imageSize);
 }