How to resize the image with ImageEditor?
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:
Sample link: