BitmapFactory.decodeStream causing “read failed: EBADF (Bad file number)” error

泪湿孤枕 提交于 2019-12-11 04:14:19

问题


I have a piece of code where use a 2-stage image loading for loading images from the SDCard.

First I use the method BitmapFactory.decodeStream to just decode the image bounds and after I use it to really load the (sampled) image.

Here is my method. I think it's derived from an example I saw here someday, but I don't remember the thread.

public static Bitmap decodeSampledBitmapFromStream(Context c, Uri uri, int reqWidth, int reqHeight) throws IOException {
    FileInputStream fis = getSourceStream(uri, c);

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(fis, null, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    fis = getSourceStream(uri, c);

    return BitmapFactory.decodeStream(fis, null, options);
}

It always worked perfectly running on real devices, but now I need to run some tests in AVD, but when I hit the line return BitmapFactory.decodeStream(fis, null, options) (the second decodeStream) I get this error:

java.io.IOException: read failed: EBADF (Bad file number)

The reading/writing sdcard permissions are set.

What should be done?

来源:https://stackoverflow.com/questions/26499123/bitmapfactory-decodestream-causing-read-failed-ebadf-bad-file-number-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!