2

需要显示从 zip 下载并提取到应用程序的“/files”目录中的图像。据我所知,图像正在正确地进入那里 - 我能够从模拟器中提取它们并从我的桌面查看/打开它们。但是到目前为止,我发现并尝试过的每一次尝试、每一种代码变体都失败了(标签:skia / 文本:---解码器->解码返回错误)。

我最新的构造,它适用于单独下载和未压缩的图像文件:

String imgFile = new File(getFilesDir(), "myImage.jpg").getAbsolutePath();

        ImageView myImageView = new ImageView(this); 
        Bitmap bm = null;
        try{

            bm = BitmapFactory.decodeFile(imgFile);
            myImageView.setImageBitmap(bm);

        } finally{

            mainLayout.addView(myImageView);
        }

这是我用来处理 zip 提取的构造。我认为这就是问题所在,但我不知道我可以做些什么不同的事情以及产生什么效果:

ZipInputStream zis = new ZipInputStream(fis);
BufferedInputStream in = new BufferedInputStream(zis, 8192);
ZipEntry ze;

while ((ze = zis.getNextEntry()) != null){
    File dest_file = new File(getFilesDir(), ze.getName());
    FileOutputStream fout = new FileOutputStream(getFilesDir() + "/" + ze.getName());
    BufferedOutputStream out = new BufferedOutputStream(fout, 8192);
    byte b[] = new byte[1024];
    int n;

    while ((n = in.read(b,0,1024)) >= 0) {
        out.write(b,0,n);
    }

    for (int c = zis.read(); c != -1; c = zis.read()) { 
        fout.write(c); 
    }

    zis.closeEntry();
    fout.close();
}
zis.close();
fis.close();

在这里陷入了可怕的停顿。感谢任何解决方案/建议。

4

0 回答 0