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 resize the image with ImageEditor?

Platform: Xamarin.Forms |
Control: SfImageEditor

By default in SfImageEditor, the image will be saved in original image size and “.jpg” format. We can also able to change the image size and image format while saving the image.

 

Step 1: 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 2: Set width and height manually and change the image saving format while Saving the image using pop-ups

 

Please refer the following code snippet to set image size and change image format while saving.

C#

 

private void Ok_Clicked(object sender, EventArgs e)
   {
     ...
     Size size = new Size(width, height);
     if(SaveFormat.SelectedIndex == 0)
     Editor.Save(".jpg", size);
     else if (SaveFormat.SelectedIndex == 1)
     Editor.Save(".png", size);
     else if (SaveFormat.SelectedIndex == 2)
     Editor.Save(".bmp", size);
   }

 

In the below code snippet, calculated width and height while respecting aspect ratio and created picker for changing the image format and passed into save method.

 

C#

 

private void WidthValue_TextChanged(object sender, TextChangedEventArgs e)
   {
     heightValue.TextChanged -= HeightValue_TextChanged;
     Int32.TryParse(widthValue.Text, out width);
     int adjustedHeight = width * originalHeight / originalWidth;
     heightValue.Text = adjustedHeight.ToString();
     heightValue.TextChanged += HeightValue_TextChanged;
   }
 
private void HeightValue_TextChanged(object sender, TextChangedEventArgs e)
  {
     widthValue.TextChanged -= WidthValue_TextChanged;
     Int32.TryParse(heightValue.Text, out height);
     int adjustedWidth = height * originalWidth / originalHeight;
     widthValue.Text = adjustedWidth.ToString();
     widthValue.TextChanged += WidthValue_TextChanged;
   }
 
private void Ok_Clicked(object sender, EventArgs e)
   {                    
      popup.IsVisible = false;
      grid.IsVisible = false;
      Int32.TryParse(widthValue.Text, out width);
      Int32.TryParse(heightValue.Text, out height);
      Size size = new Size(width, height);
      if(SaveFormat.SelectedIndex==0)
      Editor.Save(".jpg", size);
      else if (SaveFormat.SelectedIndex == 1)
      Editor.Save(".png", size);
      else if (SaveFormat.SelectedIndex == 2)
      Editor.Save(".bmp", size);
    }

 

 

Screen Shot:

 

Resize the image and change image format using xamarin SfImageEditor

 

 

Sample link:

 

https://www.syncfusion.com/downloads/support/directtrac/general/ze/ImageEditor_GettingStarted-86887888.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