2012-03-19 2 views
0

ZipInputStream을 사용하여 각 파일을 ArrayList의 아카이브 안에 저장하려고합니다. ZipInputStream으로이 작업을 수행 할 수 있습니까?File 객체에 대한 ZipInputStream

내 주요 목표는 이미지 (jpg/png) 만 포함 된 아카이브를 압축 해제하는 것입니다.이 이미지 각각을 ArrayList에 넣으려고하므로 ArrayList에 대한 ZipInputStream이 결국 가져올 계획이었습니다. 비트 맵으로 변환 할 수 있지만, ZipInputStream에서 곧바로 비트 맵으로 변환 할 수 있다면 좋을 것입니다.

+0

를 얻을 수에 있었다 4 또는 5 번 이미지에서 전체 지퍼를 통해 BitmapFactory.decodeStream (zis) 중에 항상 충돌합니다. – tantonj

답변

2

결국, 원래 계획 한대로 너무 많은 메모리를 사용했습니다! 대신 한 번에 하나의 ZipEntry를 사용하는 것으로 끝났지 만 매번마다 매번 루프를 돌릴 필요가 없었습니다.

public Bitmap getBitmapFromZip(final String zipFilePath, final String imageFileInZip){ 
    Bitmap result = null; 
try { 
    ZipEntry ze = zipfile.getEntry(imageFileInZip); 
    InputStream in = zipfile.getInputStream(ze); 
    result = BitmapFactory.decodeStream(in); 
} catch (IOException e) { 
    e.printStackTrace(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
return result; 

}는 그냥 그러나 그것은 얻을 수 없다, 시작 부분을 통해 빠르게 루프 모든 이름

public ArrayList<String> unzip() { 
    ArrayList<String> fnames = ArrayList<String>(); 
    try { 
     FileInputStream fin = new FileInputStream(_zipFile); 
     ZipInputStream zin = new ZipInputStream(fin); 
     ZipEntry ze = null; 
     while ((ze = zin.getNextEntry()) != null) { 

      if(ze.isDirectory()) { 
      } else { 
      fnames.add(ze.getName()/*fname[fname.length - 1]*/); 
      zin.closeEntry(); 
      }   
     } 
     zin.close(); 
    } catch(Exception e) { 
    } 
    return fnames; 
} 
나는 비트 맵 배열에 이미지를 넣어하는 방법 중 하나를 발견