换了新手机,照片4800万像素,BitmapFactory.decodeFile 溢出崩溃,看看别人是怎么解决的。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; //开启只读取尺寸
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
DisplayMetrics DM = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(DM);
int size = 1;
if (options.outWidth > DM.widthPixels) {
size = options.outWidth / DM.widthPixels; //计算比例
}
options.inSampleSize = size; //设置缩放值
options.inJustDecodeBounds = false; //关闭只读取尺寸
bitmap = BitmapFactory.decodeFile(path, options);
完美解决!