Search code examples
c#xamarin.formsxamarin.essentials

Best way to crop images taken by Media Picker in xamarin forms


I want to crop an image in xamarin forms with an interface that the user can crop mannualy the image taken from Xamarin.Essentials Media Picker. I´m using the MVVM pattern. I tried to use SkiaSharp, but not work properly.

Any ideas?

Thanks For helping.


Solution

  • Please Check this nuget Xamarin.Controls.ImageCropper.

    Example Code:

      Source = mediaFile.Path; // Local Path of the image
      await ImageCropper.Current.Crop(new CropSettings()
                        {
                            AspectRatioX = 0,
                            AspectRatioY = 0,
                            CropShape = CropSettings.CropShapeType.Rectangle
                        }, Source).ContinueWith(t =>
                        {
                            if (t.IsFaulted)
                            {
                                var ex = t.Exception;
                                //alert user
                            }
                            else if (t.IsCanceled)
                            {
                                //do nothing
                            }
                            else if (t.IsCompleted)
                            {
                                LocalMediaPath = t.Result;
                                //do smth with result
                            }
                        });