图片压缩
# 图片压缩
# 代码示例
String srcPath = "D:\\xx\\test.jpg";
String outPath = "D:\\xx\\out.jpg";
@Test
public void testByHutool() {
File srcFile = FileUtil.file(srcPath);
System.out.println("原图: " + srcFile.length());
System.out.println("原图(KB): " + srcFile.length() / 1024);
ImgUtil.scale(
srcFile,
FileUtil.file(outPath),
0.5f
);
System.out.println("压缩后 = " + FileUtil.file(outPath).length());
System.out.println("压缩后(KB) = " + FileUtil.file(outPath).length() / 1024);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 学习参考
上次更新: 2024/9/25 11:16:13