How to include custom cropping aspect in toolbar?
SfImageEditor allows you to include custom cropping aspect in toolbar. Crop sub toolbar has inbuilt cropping aspect toolbar item such as Free, Original, Square, 3:1, 1:3, 3:2, 2:3, 4:3, 3:4, 5:4 ,4:5, 16:9 and 9:16. You can add custom cropping aspect toolbar item to existing toolbar item collection.
Step 1: Create image editor 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: To add custom cropping aspect toolbar item to existing toolbar item collection as like below,
C#
var toolbarItem = ((ImageEditor.ToolbarSettings.ToolbarItems[3]) as FooterToolbarItem).SubItems[0] as FooterToolbarItem; toolbarItem.SubItems.Add(new Syncfusion.SfImageEditor.XForms.ToolbarItem() { Text = "5:7", Icon = ImageSource.FromResource("CustomCroppingSample.CropAspect.png") });
Step 3: On Cliking custom toolbar item, ToolbarItemSelected event will be triggered. From this, you can get selected toolbar item as an argument.
Using ToggleCropping(5,7) method, cropping can be performed based on the ratio which is passed in the arguments as like below,
C#
editor.ToolbarSettings.ToolbarItemSelected += ToolbarSettings_ToolbarItemSelected;
private void ToolbarSettings_ToolbarItemSelected(object sender, ToolbarItemSelectedEventArgs e) { var item = e.ToolbarItem as Syncfusion.SfImageEditor.XForms.ToolbarItem; if (item.Text == "5:7") { editor.ToggleCropping(5, 7); } }
Sample Link: