From 5d6c2076ec22963b7e2d4435e0c78fc48dd5ea8a Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Mon, 20 May 2019 18:01:25 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0=E4=BC=98?= =?UTF-8?q?=E5=8C=96][=E4=BF=AE=E6=94=B9]:=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/iformall/utils/ImgUtil.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/utils/ImgUtil.java b/mallinkService/src/main/java/com/iformall/utils/ImgUtil.java index 53c447423..cd94d0f0c 100644 --- a/mallinkService/src/main/java/com/iformall/utils/ImgUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/ImgUtil.java @@ -4,13 +4,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletRequest; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; public class ImgUtil { private final static Logger logger = LoggerFactory.getLogger(ImgUtil.class); @@ -23,14 +20,17 @@ public class ImgUtil { * @throws Exception */ public static File thinImage(String input, String newFile, String imgFormat) throws IOException { + File file = new File(newFile); // 输出到文件流 + File pDest = file.getParentFile(); + if (!pDest.exists()) { + pDest.mkdirs(); + } Image src = ImageIO.read(new File(input)); int width = src.getWidth(null); // 获取图源宽度 int height = src.getHeight(null); // 获取图源高度 - BufferedImage thumb = new BufferedImage(width / 1, height / 1, - BufferedImage.TYPE_INT_RGB); + BufferedImage thumb = new BufferedImage(width / 1, height / 1, BufferedImage.TYPE_INT_RGB); // 绘制缩小后的图 thumb.getGraphics().drawImage(src, 0, 0, width / 1, height / 1, null); - File file = new File(newFile); // 输出到文件流 ImageIO.write(thumb, imgFormat, file); return file; }