開發(fā)逗萁上遇到很奇怪的BUG
public Bitmap decodeSampledBitmapFromFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(fd, null, options);
}
最后返回那一句
return BitmapFactory.decodeFileDescriptor(fd, null, options);
配置高的手機(jī)上面沒有問題,但是配置低的手機(jī)如HM NOTE 1LTE上面時(shí)常返回null,百思不得其解。(但是真機(jī)調(diào)試時(shí)又是正常的,不知道是不是調(diào)試的時(shí)候內(nèi)存沒限制)
最后使用了BitmapFactory.decodeFile解決了
public Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
這樣就算在HM NOTE 1LTE這種配置低的機(jī)子上也不會返回null