Android大画像の効率的な読み取りによるOOM防止
691 ワード
ツールメソッド
public static Bitmap getImageFromAssetsFile1(Context context, String fileName) {
Bitmap image = null;
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
byte[] bytes = new byte[1024];//
int len=0;
AssetManager am = context.getResources().getAssets();
try {
InputStream is = am.open(fileName);
while((len=is.read(bytes))!=-1){
outputStream.write(bytes, 0, len);//
}
byte[] result=outputStream.toByteArray();//
image = BitmapFactory.decodeByteArray(result, 0, result. length);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return image;
}