wuweihao 3 år sedan
förälder
incheckning
9ac312556f

+ 8 - 3
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/ImgUtils.java

@@ -74,16 +74,21 @@ public class ImgUtils {
      * @param file
      */
     public static void checkImgRatio(MultipartFile file){
+        BufferedImage read = null;
         try {
             ImageIO.setUseCache(false);
-            BufferedImage read = ImageIO.read(file.getInputStream());
+            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();
+            }
         }
 
     }