Android 同一路径的BitmapFactory.decodeFile返回null
问题是,即使路径相同,但decodefile函数有时在调用该函数时返回nullAndroid 同一路径的BitmapFactory.decodeFile返回null,android,image,bitmap,decode,Android,Image,Bitmap,Decode,问题是,即使路径相同,但decodefile函数有时在调用该函数时返回null public static Bitmap lessResolution(String filePath, int width, int height) { int reqHeight = width; int reqWidth = height; BitmapFactory.Options options = new BitmapFactory.Options(); options.
public static Bitmap lessResolution(String filePath, int width, int height) {
int reqHeight = width;
int reqWidth = height;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
//BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
options.inJustDecodeBounds = false;
Bitmap b = BitmapFactory.decodeFile(filePath, options);
Log.d("test1","f:" + filePath);
Log.d("test1","b:" + b);
return b;
}
在成功案例中:
02-10 09:28:23.554 22444-22444/? D/test1: f:/storage/emulated/0/MyApp/1486690065.jpg
02-10 09:28:23.554 22444-22444/? D/test1: b:android.graphics.Bitmap@8756c
在失败的情况下:
02-10 09:29:22.425 22444-22444/? D/test1: f:/storage/emulated/0/MyApp/1486690065.jpg
02-10 09:29:22.425 22444-22444/? D/test1: b:null
非常感谢您的帮助。我有一个类似的代码正在运行,但是使用了BitmapFactory.decodeFile(文件路径,选项);未注释的汉克斯。取消注释将给出相同的结果