Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformException(crop_error, y + height must be <= bitmap.height(), java.lang.IllegalArgumentException: y + height must be <= bitmap.height() #537

Open
dharambudh1 opened this issue Nov 29, 2024 · 0 comments

Comments

@dharambudh1
Copy link

I'm encountering an issue after cropping an image on the Android side.

PlatformException(crop_error, y + height must be <= bitmap.height(), java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
	at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
	at android.graphics.Bitmap.createBitmap(Bitmap.java:880)
	at com.yalantis.ucrop.task.BitmapCropTask.crop(BitmapCropTask.java:165)
	at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:105)
	at com.yalantis.ucrop.task.BitmapCropTask.doInBackground(BitmapCropTask.java:37)
	at android.os.AsyncTask$3.call(AsyncTask.java:394)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
	at java.lang.Thread.run(Thread.java:1012)
, null)

Here are the steps to reproduce the issue:

  1. Set the aspect ratio to 16:9.
  2. Select an image.
  3. Drag the crop box down to the very bottom of the image.
  4. Tap the checkmark button in the top-right corner.

Video footage:

Screen.Recording.Nov.29.2024.mp4

My code:

  Future<CroppedFile?> cropImage({
    required String sourcePath,
    CropAspectRatioPreset preset = CropAspectRatioPreset.original,
  }) async {
    CroppedFile? croppedFile;

    try {
      final (int, int)? value = getCropAspectRatioPreset(preset);
      final double ratioX = double.parse((value?.$1 ?? "0.0").toString());
      final double ratioY = double.parse((value?.$2 ?? "0.0").toString());
      croppedFile = await cropper.cropImage(
        sourcePath: sourcePath,
        aspectRatio: value != null
            ? CropAspectRatio(ratioX: ratioX, ratioY: ratioY)
            : null,
      );
      AppLogger().info(message: "cropImage() file: ${croppedFile?.path ?? ""}");
    } on Exception catch (err, stack) {
      AppLogger().error(message: "Exception caught", err: err, stack: stack);
    } finally {}

    return Future<CroppedFile?>.value(croppedFile);
  }

  (int, int)? getCropAspectRatioPreset(CropAspectRatioPreset preset) {
    (int, int)? value;

    switch (preset) {
      case CropAspectRatioPreset.square:
        value = (1, 1);
        break;
      case CropAspectRatioPreset.ratio3x2:
        value = (3, 2);
        break;
      case CropAspectRatioPreset.ratio4x3:
        value = (4, 3);
        break;
      case CropAspectRatioPreset.ratio5x3:
        value = (5, 3);
        break;
      case CropAspectRatioPreset.ratio5x4:
        value = (5, 4);
        break;
      case CropAspectRatioPreset.ratio7x5:
        value = (7, 5);
        break;
      case CropAspectRatioPreset.ratio16x9:
        value = (16, 9);
        break;
      case CropAspectRatioPreset.original:
        value = null;
        break;
    }

    return value;
  }

@hnvn Could you please take a look at this? This library is a critical component of our project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant