Skip to content

Commit 80a5fd5

Browse files
committed
fixed inSampleSize calculation
1 parent 4d3623e commit 80a5fd5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected BitmapWorkerResult doInBackground(Void... params) {
9090
}
9191

9292
final BitmapFactory.Options options = new BitmapFactory.Options();
93-
options.inJustDecodeBounds = true;
93+
BitmapLoadUtils.decodeDimensions(context, mInputUri, options);
9494
options.inSampleSize = BitmapLoadUtils.calculateInSampleSize(options, mRequiredWidth, mRequiredHeight);
9595
options.inJustDecodeBounds = false;
9696

ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ public static Bitmap transformBitmap(@NonNull Bitmap bitmap, @NonNull Matrix tra
5353
return bitmap;
5454
}
5555

56+
public static void decodeDimensions(@NonNull Context context, @NonNull Uri uri, @NonNull BitmapFactory.Options options) {
57+
options.inJustDecodeBounds = true;
58+
try {
59+
InputStream is = context.getContentResolver().openInputStream(uri);
60+
try {
61+
BitmapFactory.decodeStream(is, null, options);
62+
} finally {
63+
BitmapLoadUtils.close(is);
64+
}
65+
} catch (IOException ignored) {
66+
}
67+
}
68+
5669
public static int calculateInSampleSize(@NonNull BitmapFactory.Options options, int reqWidth, int reqHeight) {
5770
// Raw height and width of image
5871
final int height = options.outHeight;

0 commit comments

Comments
 (0)