Răsfoiți Sursa

缩放图片支持限制最大宽高

懒得勤快 3 ani în urmă
părinte
comite
867715d525

+ 8 - 0
Masuit.Tools.Abstractions/Media/ImageUtilities.cs

@@ -762,6 +762,14 @@ namespace Masuit.Tools.Media
                     towidth = originalImage.Width * height / originalImage.Height;
                     break;
 
+                case ThumbnailCutMode.LockHeightAndWidth: //指定高,宽按比例
+                    towidth = originalImage.Width * height / originalImage.Height;
+                    towidth = towidth > width ? width : towidth;
+                    toheight = originalImage.Height * towidth / originalImage.Width;
+                    toheight = toheight > height ? height : toheight;
+                    towidth = originalImage.Width * toheight / originalImage.Height;
+                    break;
+
                 case ThumbnailCutMode.Cut: //指定高宽裁减(不变形)
                     if (originalImage.Width / (double)originalImage.Height > towidth / (double)toheight)
                     {

+ 6 - 1
Masuit.Tools.Abstractions/Media/ThumbnailCutMode.cs

@@ -15,6 +15,11 @@
         /// </summary>
         LockWidth,
 
+        /// <summary>
+        /// 锁定最大宽高等比缩放
+        /// </summary>
+        LockHeightAndWidth,
+
         /// <summary>
         /// 固定宽高
         /// </summary>
@@ -25,4 +30,4 @@
         /// </summary>
         Cut
     }
-}
+}