TOCropViewController icon indicating copy to clipboard operation
TOCropViewController copied to clipboard

Wrong image size after pressing "Done" button without any changes, or after restoring to default image.

Open alexey-serdykov opened this issue 5 years ago • 2 comments

Hi, I'm using your framework in my app, it's cool, but I found some small issues: I present cropViewController with image with size (width: 1200.0, height: 1600.0) then press "Done" button without any changes(or crop and restore without dismissing the controller) and I get image with size (width: 1200.0, height: 1599.0) in the didCropToImage method. The same size is in the cropRect.

alexey-serdykov avatar Sep 17 '19 11:09 alexey-serdykov

Hello! Do you have any ideas about this bug?

IlyaMakarevich avatar Sep 24 '20 10:09 IlyaMakarevich

Just duplicating my answer here.

I didn't try to fix this bug exactly in the pod(I looked up and there's problem with rounding in the calculations), but I found out how to deal with this bug. In my case, I just needed to know whether the image was cropped or not, and if it was cropped to take the crop data. So, I do a little trick, in the

func cropViewController(_ cropViewController: CropViewController, didCropImageToRect rect: CGRect, angle: Int)

or in the

func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int)

delagate methods and I check the reset button's state there. If the button is enabled, then the image was cropped.

func cropViewController(_ cropViewController: CropViewController, didCropImageToRect rect: CGRect, angle: Int) {
    let isImageCropped = cropViewController.toolbar.resetButton.isEnabled

    if isImageCropped {
        // The image is cropped, we can use the returned data.
    } else {
        // The image is not cropped.
    }
}

alexey-serdykov avatar Sep 27 '20 03:09 alexey-serdykov