Skip to content

Commit

Permalink
Merge pull request #694 from Yalantis/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
severianremi authored Aug 20, 2020
2 parents 1127920 + f418322 commit 4966845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<provider
Expand Down
13 changes: 12 additions & 1 deletion ucrop/src/main/java/com/yalantis/ucrop/task/BitmapLoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class BitmapLoadTask extends AsyncTask<Void, Void, BitmapLoadTask.BitmapW

private static final String TAG = "BitmapWorkerTask";

private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB

private final Context mContext;
private Uri mInputUri;
private Uri mOutputUri;
Expand Down Expand Up @@ -106,6 +108,7 @@ protected BitmapWorkerResult doInBackground(Void... params) {
} finally {
BitmapLoadUtils.close(stream);
}
if (checkSize(decodeSampledBitmap, options)) continue;
decodeAttemptSuccess = true;
} catch (OutOfMemoryError error) {
Log.e(TAG, "doInBackground: BitmapFactory.decodeFileDescriptor: ", error);
Expand Down Expand Up @@ -243,4 +246,12 @@ protected void onPostExecute(@NonNull BitmapWorkerResult result) {
}
}

}
private boolean checkSize(Bitmap bitmap, BitmapFactory.Options options) {
int bitmapSize = bitmap != null ? bitmap.getByteCount() : 0;
if (bitmapSize > MAX_BITMAP_SIZE) {
options.inSampleSize *= 2;
return true;
}
return false;
}
}

0 comments on commit 4966845

Please sign in to comment.