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

(Bitmap OOM) BitmapFactory.nativeDecodeStream

2015-12-16 10:55 176 查看
/**
* 一种挺有效的方法,规避BitmapFactory.decodeStream或者decodeFile函数,使用BitmapFactory.decodeFileDescriptor
* @param path
* @return
*/
public static Bitmap readBitmapByPath(String path) {
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false;
bfOptions.inPurgeable=true;
bfOptions.inInputShareable=true;
bfOptions.inTempStorage=new byte[32 * 1024];

File file=new File(path);
FileInputStream fs=null;
try {
fs = new FileInputStream(file);
if(fs!=null)
return BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions);
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fs!=null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android bitmap oom