We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to save the image after cropping in ImageEditor?

Platform: Xamarin.Forms |
Control: SfImageEditor |
Published Date: November 13, 2018 |
Last Revised Date: June 24, 2019

This section explains how to save image after cropping the image in imageeditor.

 Create SfImageEditor sample with all necessary assemblies.

Please refer the below link to create a simple SfImageEditor sample along with the ways to configure it.

https://help.syncfusion.com/xamarin/sfimageeditor/getting-started

 

Step 1: Add toggle cropping method in image loaded event to show the cropping window when image loads in image editor as like below code snippet

 

 
editor.ImageLoaded += CropEditor_ImageLoaded;
private void CropEditor_ImageLoaded(object sender, ImageLoadedEventArgs args)
        {
            editor.ToggleCropping();
        }

 

 

Step 2: To save the image after cropping, you need to perform operations such as Select crop toolbar item to crop the image and select save toolbar item to save the image.

 

To avoid this too many operations to perform save the image after cropping, you need to include the toolbar item selected event and then call save method in ok click event as like below code snippet

 

 
editor.ToolbarSettings.ToolbarItemSelected += ToolbarSettings_ToolbarItemSelected;
 
private void ToolbarSettings_ToolbarItemSelected(object sender, ToolbarItemSelectedEventArgs e)
        {
            if (e.ToolbarItem.Name == "Ok")
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (Device.RuntimePlatform == Device.UWP)
                    {
                        Device.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
                        {
                            editor.Save();
 
                            return false;
                        });
 
                    }
                    else
                    {
                        editor.Save();
 
                    }
                });
            }
            if (e.ToolbarItem.Name == "Cancel")
            {
                DisplayAlert("Cancel", "Crop Cancelled", "Ok");
 
            }
        }

 

 

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/IESample278277967.zip

 

 

 

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile