安卓:导出图像压缩 [英] Android: Export images to zip

查看:138
本文介绍了安卓:导出图像压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能帮助我,在我的应用程序,我想从库中导出我的图片为.zip,但我不知道我需要做的。我会很感激任何提示

Could someone help me, in my application I would like to export my images from gallery to .zip, but I have no idea what I need to do that. I will be grateful for any tips

推荐答案

这是一些基本的拉链code。从本质上创建一个字符串数组,其中包含所有你想要在zip和另一个字符串为您的zip文件的目标路径,包括映像文件的路径。关于该方法通过这些

This is some basic zip code. Essentially create a string array containing all the image file paths you want to include in the zip and another string for the destination path of your zip file. Pass these on to the method.

public static void zip(String[] files, String zipFile) throws IOException {
BufferedInputStream origin = null;
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
try { 
    byte data[] = new byte[BUFFER_SIZE];

    for (int i = 0; i < files.length; i++) {
        FileInputStream fi = new FileInputStream(files[i]);    
        origin = new BufferedInputStream(fi, BUFFER_SIZE);
        try {
            ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
            out.putNextEntry(entry);
            int count;
            while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                out.write(data, 0, count);
            }
        }
        finally {
            origin.close();
        }
    }
}
finally {
    out.close();
}

}

或者,您可以使用 Zip4j 库。

编程快乐! :D

这篇关于安卓:导出图像压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆