Skip to content

Commit 4966845

Browse files
authored
Merge pull request #694 from Yalantis/develop
Develop to master
2 parents 1127920 + f418322 commit 4966845

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<application
1010
android:allowBackup="false"
1111
android:icon="@mipmap/ic_launcher"
12+
android:requestLegacyExternalStorage="true"
1213
android:label="@string/app_name"
1314
android:theme="@style/AppTheme">
1415
<provider

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class BitmapLoadTask extends AsyncTask<Void, Void, BitmapLoadTask.BitmapW
3737

3838
private static final String TAG = "BitmapWorkerTask";
3939

40+
private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
41+
4042
private final Context mContext;
4143
private Uri mInputUri;
4244
private Uri mOutputUri;
@@ -106,6 +108,7 @@ protected BitmapWorkerResult doInBackground(Void... params) {
106108
} finally {
107109
BitmapLoadUtils.close(stream);
108110
}
111+
if (checkSize(decodeSampledBitmap, options)) continue;
109112
decodeAttemptSuccess = true;
110113
} catch (OutOfMemoryError error) {
111114
Log.e(TAG, "doInBackground: BitmapFactory.decodeFileDescriptor: ", error);
@@ -243,4 +246,12 @@ protected void onPostExecute(@NonNull BitmapWorkerResult result) {
243246
}
244247
}
245248

246-
}
249+
private boolean checkSize(Bitmap bitmap, BitmapFactory.Options options) {
250+
int bitmapSize = bitmap != null ? bitmap.getByteCount() : 0;
251+
if (bitmapSize > MAX_BITMAP_SIZE) {
252+
options.inSampleSize *= 2;
253+
return true;
254+
}
255+
return false;
256+
}
257+
}

0 commit comments

Comments
 (0)