Skip to content

Commit

Permalink
fixed inSampleSize calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
yushaojian13 committed Jan 23, 2022
1 parent 4d3623e commit 80a5fd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 80a5fd5

Please sign in to comment.