关于BitmapFactory.decodeFileDescriptor return null

开发逗萁上遇到很奇怪的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);
配置高的手机上面没有问题,但是配置低的手机如HM NOTE 1LTE上面时常返回null,百思不得其解。(但是真机调试时又是正常的,不知道是不是调试的时候内存没限制)
最后使用了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这种配置低的机子上也不会返回null

你可能感兴趣的:(关于BitmapFactory.decodeFileDescriptor return null)