1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| 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");
}
|