Category / Section
How to use Image Editor as signature?
2 mins read
Signature pads are used for users who often need to add signatures in documents. You can achieve this by using image editor. By using image editor control, you can achieve free hand drawing, erase the content, perform Undo, Redo, reset options, and save as image to device’s gallery.
Step 1: Create an 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: Create an instance for image editor. By default, image editor loads without image.
The following code snippet illustrates how to achieve this method by using image editor.
Xaml:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SfImageEditor_GettingStarted.SfimageEditor" xmlns:local="clr-namespace:SfImageEditor_GettingStarted" xmlns:imageeditor="clr-namespace:Syncfusion.SfImageEditor.XForms;assembly=Syncfusion.SfImageEditor.XForms"> <Grid> <imageeditor:SfImageEditor Grid.RowSpan="6" x:Name="editor" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> </imageeditor:SfImageEditor> <Button WidthRequest="50" Image="Reset.png" Clicked="Reset_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="0" HorizontalOptions="End" VerticalOptions="Center"/> <Button WidthRequest="50" Image="Save.png" Clicked="Save_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="1" HorizontalOptions="End" VerticalOptions="Center"/> <Button WidthRequest="50" Image="Pen.png" Clicked="Pen_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="2" HorizontalOptions="End" VerticalOptions="Center"/> < Button WidthRequest="50" Image="Eraser.png" Clicked="Eraser_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="3" HorizontalOptions="End" VerticalOptions="Center"/> < Button WidthRequest="50" Image="Redo.png" Clicked="Redo_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="4" HorizontalOptions="End" VerticalOptions="Center"/> < Button WidthRequest="50" Image="Undo.png" Clicked="Undo_Clicked" BorderRadius="20" BorderWidth="3" BackgroundColor="Transparent" Grid.Row="5" HorizontalOptions="End" VerticalOptions="Center"/> </Grid> </ContentPage>
C#
public partial class SfimageEditor : ContentPage { public SfimageEditor() { InitializeComponent(); this.editor.ToolbarSettings.IsVisible = false; } public void Pen_Clicked(object sender, EventArgs e) { editor.AddShape(Syncfusion.SfImageEditor.XForms.ShapeType.Path); } public void Undo_Clicked(object sender, System.EventArgs e) { editor.Undo(); } public void Redo_Clicked(object sender, System.EventArgs e) { editor.Redo(); } public void Reset_Clicked(object sender, System.EventArgs e) { editor.Reset(); } public void Save_Clicked(object sender, System.EventArgs e) { editor.Save(); } public void Eraser_Clicked(object sender, System.EventArgs e) { editor.AddShape(Syncfusion.SfImageEditor.XForms.ShapeType.Path, new Syncfusion.SfImageEditor.XForms.PenSettings() { Color = Color.White, StrokeWidth = 20 }); }
Sample Link:
Screen Shot: