2012-02-02 11 views
0

私はアンドロイドの内部ストレージから画像を表示しようとしていますが、画像は4枚しかありません(画像はスクリーンショットです)それは動作しますが、それはあまりにも多くの時間を要し、これは私のコードです:アンドロイド内部のストレージから1バイトずつ画像を読み込むには時間がかかります

FileInputStream fis = null; 
DataOutputStream outWriter = null; 
ByteArrayOutputStream bufStream = null; 
String imageFile; 
int occurence; 
for (int i=0; i<4; i++) { 
    try { 
     occurence = i+1; 
     imageFile = "preview"+occurence+".png"; 
     fis = openFileInput(imageFile); 
     bufStream = new ByteArrayOutputStream(); 
     outWriter = new DataOutputStream(bufStream); 
    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    int ch; 
    byte[] data = null; 
    try { 
     **while((ch = fis.read()) != -1) 
      outWriter.write(ch);** 
     outWriter.close(); 
     data = bufStream.toByteArray(); 
     bufStream.close(); 
     fis.close(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    favorPreviews.add(BitmapFactory.decodeByteArray(data, 0, data.length)) ; 
} 

あなたが見ることができるように、私はそれらを読むためのFileInputStreamを使用していますが、それはファイルがこのループにバイト単位で読み取ります。

while((ch = fis.read()) != -1) 
    outWriter.write(ch); 

これは時間がかかりすぎるため、誰でもこれらの画像をより速く読む方法を知っていますか?

答えて

1

画像サイズを小さくするためには、より速く表示されます。それはBitmap decodeFile (String pathName, BitmapFactory.Options opts)

ルックこの例で使用して行うことができます。

public Bitmap getReducedBitmap(String path) { 
    BitmapFactory.Options opt = new BitmapFactory.Options(); 
    opt.inSampleSize=4; // reduced the image to 1/4 of the orignal size 
    return BitmapFactory.decodeFile(path, opt); 
} 
+0

おかげで多くのことを、私はそれをしようとします –