我创建了带有图像的zip文件的代码,如下所示
public void zip(String[] files, String zipFile) {
final String[] _files = files;
final String _zipFile = zipFile;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(_zipFile);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
byte data[] = new byte[BUFFER];
for (int i = 0; i < _files.length; i++) {
Log.d("add:", _files[i]);
Log.v("Compress", "Adding: " + _files[i]);
FileInputStream fi = new FileInputStream(_files[i]);
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(_files[i].substring(_files[i].lastIndexOf("/") + 1));
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
我打电话给方法zip(stockArr,&#34; /storage/sdcard0/MyAnnouncementImages.zip"),图片没有被压缩然后如果每张图片重3Mb,那么zip文件将是如此沉重,那么我需要在放入zip文件之前压缩每个图像,有些帮助吗?
答案 0 :(得分:0)
您尝试使用Bitmap吗?
Bitmap bitmap = Bitmap.createScaledBitmap(capturedImage, width, height, true);
指定位图的宽度和高度,以便...根据设备的屏幕dpi设置的高度和宽度。