问题
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