Android(安卓)decodeFile OutOfMemory
16lz
2021-01-26
FileInputStream fs = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outWidth = 10;
options.outHeight = 10;
options.inSampleSize = 10;// 特别注意,这个值越大,相片质量越差,图像越小
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
options.inPurgeable = true;
options.inInputShareable = true;
options.inDither = false;
options.inTempStorage = new byte[12 * 1024];
try {
fs = new FileInputStream(new File(filePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
drawable = BitmapFactory.decodeFileDescriptor(fs.getFD(),
null, options);
imgMaps.put(filePath, new SoftReference<Bitmap>(drawable));
} catch (Exception e) {
return null;
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.outWidth = 10;
options.outHeight = 10;
options.inSampleSize = 10;// 特别注意,这个值越大,相片质量越差,图像越小
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
options.inPurgeable = true;
options.inInputShareable = true;
options.inDither = false;
options.inTempStorage = new byte[12 * 1024];
try {
fs = new FileInputStream(new File(filePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
drawable = BitmapFactory.decodeFileDescriptor(fs.getFD(),
null, options);
imgMaps.put(filePath, new SoftReference<Bitmap>(drawable));
} catch (Exception e) {
return null;
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
更多相关文章
- Android开源框架----1. SmartImageView图像视图
- Android(安卓)识别手指个数
- Android(安卓)使用OPENCV实现图像实时对比
- 初学Android,图形图像之使用drawBitmapMesh扭曲图像(三十二)
- 你不知道的Android着色器/渲染器
- Android中的图像处理
- Android(安卓)Paint之shader(图像渲染)
- Android中的SurfaceTexture
- Android(安卓)Bitmap图像效果处理