public static void processImagesToZip(HttpServletResponse response, List<String> ossList) throws IOException {
// 将 OSS 图片地址转换成图片文件
List<File> fileList = new ArrayList<>();
for (String ossUrl : ossList) {
try {
BufferedImage image = ImageIO.read(new URL(ossUrl));
//
String fileName = ossUrl.substring(ossUrl.lastIndexOf("/") + 1)+ UUID.randomUUID()+".jpg";
File file = new File(fileName);
ImageIO.write(image, "jpg", file);
fileList.add(file);
} catch (IOException e) {
e.printStackTrace();
}
}
// 打包压缩图片文件
File zipFile = new File("kouqiang.zip");
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile))) {
byte[] buffer = new byte[1024];
for (File file : fileList) {
if (file.exists()) {
ZipEntry zipEntry = new ZipEntry(file.getName());
zipOut.putNextEntry(zipEntry);
将图片链接转换成图片打成压缩包的工具类(有直接打包, 有分文件夹打包的)
猜你喜欢
转载自blog.csdn.net/weixin_42759398/article/details/131607769
今日推荐
周排行