Forum Xamarin.iOS

TOCrop - get image After Crop

AgrimaldoAgrimaldo Member ✭✭

I'm new in Mobile Development (IOS) and I'm stuck with a problem : I'm using TOCropViewController to crop images, but not find how to get image cropped and put in a UIImageView, how I do this?

thanks for help


  • jeremieHelmejeremieHelme FRMember

    Hey Agrimaldo,

    You have to create a delegate class to handle the DidCropToImage function (and other functions if needed)

    You can create a class to be the Delegate

    class CropVCDelegate : TOCropViewControllerDelegate
            public event EventHandler<UIImage> CroppedToImage;
            public override void DidCropToImage(TOCropViewController cropViewController, UIKit.UIImage image, CoreGraphics.CGRect cropRect, nint angle)
                CroppedToImage?.Invoke(this, image); //here I fire my own event when the image is ready

    And assign the Delegate to an instance of this class

    cropDelegate = new CropVCDelegate();
    cropDelegate.CroppedToImage += onImageCropped; //here I listen to my event
    cropVC = new TOCropViewController(TOCropViewCroppingStyle.Default, image);
    cropVC.Delegate = cropDelegate;
    this.PresentViewController(cropVC, true, null);
    private void onImageCropped(object sender, UIImage e)
                //do what you want with the UIImage e
                cropVC.DismissViewController(true, null);
  • AgrimaldoAgrimaldo Member ✭✭

    thanks for the answer.

Sign In or Register to comment.