From 184e2c9ec5d93965c818a5801439f54d3dfebd7c Mon Sep 17 00:00:00 2001 From: 王煜鑫 <wyx@iemsoft.cn> Date: Tue, 06 Nov 2018 09:45:05 +0800 Subject: [PATCH] 更新权限接口 --- sourcecode/MVNFHM/src/main/java/com/fh/util/Watermark.java | 16 ++++------------ 1 files changed, 4 insertions(+), 12 deletions(-) diff --git a/sourcecode/MVNFHM/src/main/java/com/fh/util/Watermark.java b/sourcecode/MVNFHM/src/main/java/com/fh/util/Watermark.java index 6593d57..685da0b 100644 --- a/sourcecode/MVNFHM/src/main/java/com/fh/util/Watermark.java +++ b/sourcecode/MVNFHM/src/main/java/com/fh/util/Watermark.java @@ -10,8 +10,6 @@ import javax.imageio.ImageIO; -import com.sun.image.codec.jpeg.JPEGCodec; -import com.sun.image.codec.jpeg.JPEGImageEncoder; /** * 说明:图片水印处理类 (报错注意:用安装版的jdk,不要用开发工具自带的jdk) @@ -74,7 +72,7 @@ */ public final static void pressImage(String pressImg, String targetImg, int x, int y) { - try { + try (FileOutputStream out = new FileOutputStream(targetImg)){ //目标文件 File _file = new File(targetImg); Image src = ImageIO.read(_file); @@ -94,10 +92,7 @@ g.drawImage(src_biao, x, y, wideth_biao, height_biao, null); //水印文件结束 g.dispose(); - FileOutputStream out = new FileOutputStream(targetImg); - JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); - encoder.encode(image); - out.close(); + ImageIO.write(image, "jpg", out); } catch (Exception e) { e.printStackTrace(); } @@ -125,7 +120,7 @@ public static void pressText(String pressText, String targetImg, String fontName, int fontStyle, Color color, int fontSize, int x,int y) { - try { + try (FileOutputStream out = new FileOutputStream(targetImg)){ File _file = new File(targetImg); Image src = ImageIO.read(_file); int wideth = src.getWidth(null); @@ -138,10 +133,7 @@ g.setFont(new Font(fontName, fontStyle, fontSize)); g.drawString(pressText, x, y); g.dispose(); - FileOutputStream out = new FileOutputStream(targetImg); - JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); - encoder.encode(image); - out.close(); + ImageIO.write(image, "jpg", out); } catch (Exception e) { System.out.println(e); } -- Gitblit v1.8.0