diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java index 72784e5b5..429ebea67 100755 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java @@ -90,7 +90,7 @@ protected BitmapWorkerResult doInBackground(Void... params) { } final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; + BitmapLoadUtils.decodeDimensions(context, mInputUri, options); options.inSampleSize = BitmapLoadUtils.calculateInSampleSize(options, mRequiredWidth, mRequiredHeight); options.inJustDecodeBounds = false; diff --git a/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java b/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java index 5e482f689..6210a0ad0 100755 --- a/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java @@ -53,6 +53,19 @@ public static Bitmap transformBitmap(@NonNull Bitmap bitmap, @NonNull Matrix tra return bitmap; } + public static void decodeDimensions(@NonNull Context context, @NonNull Uri uri, @NonNull BitmapFactory.Options options) { + options.inJustDecodeBounds = true; + try { + InputStream is = context.getContentResolver().openInputStream(uri); + try { + BitmapFactory.decodeStream(is, null, options); + } finally { + BitmapLoadUtils.close(is); + } + } catch (IOException ignored) { + } + } + public static int calculateInSampleSize(@NonNull BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight;