bthurlow / nativescript-imagecropper

A nativescript image cropping plugin.
Other
49 stars 35 forks source link

Crashes when width/height options set on iOS #74

Open mreall opened 3 years ago

mreall commented 3 years ago

If the demo apps cannot help and there is no issue for your problem, tell us about it

I upgraded to the latest version (4.0.1) and now when I pass in a width and height to the show() method per the instructions it throws an error. Stepping through the debugger, it looks like UIGraphicsGetImageFromCurrentImageContext() in imagecropper.ios.js is returning null.

Passing a width and height prior to upgrading worked fine. Also, if I don't pass a width and height, the cropper works as expected.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

mreall commented 3 years ago

As a workaround, I resize the image before sending it to the cropper using the ImageAsset object.

const context = imagepicker.create(options);
context
  .authorize()
  .then(() => context.present())
  .then((selection) => {
    let asset = selection[0];
    asset.options = {
      width: newWidth,
      height: newHeight,
      keepAspectRatio: true,
      autoScaleFactor: false,
    };

    ImageSource.fromAsset(asset).then((image) => {
      const imageCropper = new ImageCropper();
      imageCropper
        .show(image, {
          //width: newWidth,
          //height: newHeight,
          lockSquare: true,
          circularCrop: true,
        })
        .then((args) => {
          // Process the cropped image.
        })
    });
  });