图片比例压缩
点关注不迷路,欢迎再访!
1.引入依赖:
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
2.实现压缩代码:
BufferedImage img = ImageIO.read(new File("D:/images/aa.png"));
File outFile = new File("D:/images/cc.png");
Thumbnails.of(img)
.scale(0.25f) //0-1f 图片压缩比例,接近0失真
.outputQuality(1f) //默认为1
.toFile(outFile);