浏览代码

测试io-4

wuweihao 3 年之前
父节点
当前提交
c6fdf6018d
共有 1 个文件被更改,包括 5 次插入7 次删除
  1. 5 7
      720yun_local_manage/gis_common/src/main/java/com/gis/common/util/ImgUtils.java

+ 5 - 7
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/ImgUtils.java

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 
@@ -69,19 +70,16 @@ public class ImgUtils {
      * @param file
      */
     public static void checkImgRatio(MultipartFile file){
-        BufferedImage read = null;
         try {
-            read = ImgUtil.read(file.getInputStream());
+
+            BufferedImage read = ImageIO.read(file.getInputStream());
             int width = read.getWidth();
             int height = read.getHeight();
+            // 释放内存
+            read.getGraphics().dispose();
             BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
         } catch (IOException e) {
             e.printStackTrace();
-        } finally {
-            if (read != null){
-                // 释放内存
-                read.getGraphics().dispose();
-            }
         }
 
     }