java进行图片压缩
图片压缩
添加依赖
<dependency>
<groupId>com.siashan</groupId>
<artifactId>toolkit-image</artifactId>
<version>1.1.9</version>
</dependency>
使用Thumbnails来进行图片压缩
public static void compressImage(String path,
int width, int height,
String suffix,
String outputFilename) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedImage image = Thumbnails.of(path)
.size(width, height)
.outputFormat(suffix)
.asBufferedImage();
ImageIO.write(image,suffix, new File(outputFilename));
} catch (IOException e) {
}
}
public static void main(String[] args) {
compressImage("/Users/zhanghe/Desktop/线上问题查找.png", 1048, 1000,"png",
"/Users/zhanghe/Desktop/Optimize.png");
}
参考文献
本文来自博客园,作者:拾光师,转载请注明原文链接:https://www.cnblogs.com/life-time/p/18657785 个人博客-> https://zhhll.icu

浙公网安备 33010602011771号