|
@@ -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();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|