Browse Source

[图片上传优化][修改]:图片上传优化

release_toaliyun_real
Stormeye Wu 7 years ago
parent
commit
5d6c2076ec
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      mallinkService/src/main/java/com/iformall/utils/ImgUtil.java

+ 6
- 6
mallinkService/src/main/java/com/iformall/utils/ImgUtil.java View File

@@ -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;
}


Loading…
Cancel
Save