#408·uCrop

Crash during crop bitmap creation (x + width must be <= bitmap.width())

Author: gavriilCreated Apr 16, 2018Updated Sep 11, 2026
Labelsbug

Hi uCrop team!

I have integrated uCrop using following code: val sourceUri = data.data val destinationUri = Uri.fromFile(File(getCacheDir(), "photoFromGallery.jpg")) val ratioX = cameraView.measuredWidth.toFloat() val ratioY = cameraView.measuredHeight.toFloat() val options = UCrop.Options() options.setToolbarColor(ContextCompat.getColor(context, R.color.gallery_primary)) options.setStatusBarColor(ContextCompat.getColor(context, R.color.gallery_dark)) options.setToolbarTitle(context.getString(R.string.gallery_edit_photo)) UCrop.of(sourceUri, destinationUri) .withAspectRatio(ratioX, ratioY) .withMaxResultSize(MAX_PHOTO_SIZE, MAX_PHOTO_SIZE) .withOptions(options) .start(context, this)

It works just fine in most cases. Thank you! But we have found the following crashes in crashlytics (about 30 crashes per week):

Caused by java.lang.IllegalArgumentException: x + width must be <= bitmap.width() at android.graphics.Bitmap.createBitmap(Bitmap.java:826) at android.graphics.Bitmap.createBitmap(Bitmap.java:793) at com.yalantis.ucrop.task.BitmapCropTask.crop(SourceFile:152) at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(SourceFile:95) at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(SourceFile:35) at android.os.AsyncTask$2.call(AsyncTask.java:304) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762)

Not sure how to reproduce it. Could you, please, fix it? Maybe I can change the client code to avoid this crash?

uCrop version 2.2.1.
android versions