您的位置:首页 > 移动开发 > Android开发

android高效读取大图片 防止OOM

2016-03-31 00:00 459 查看
工具方法

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: