Articles in this section
Category / Section

How to Save Signature as Byte Array in .NET MAUI SignaturePad Control?

2 mins read

This article demonstrates how to save a signature as a byte array using the .NET MAUI SignaturePad control. Follow the steps below.

Step 1: Initialize the SignaturePad Control

XAML

<VerticalStackLayout Padding="50,0,50,0" Spacing="10">
   <Label Text="Signature:" FontSize="20" FontAttributes="Bold" FontFamily="OpenSansSemibold"/>
   <Frame>
       <sign:SfSignaturePad x:Name="signaturePad" Background="WhiteSmoke" HeightRequest="200" DrawCompleted="SfSignaturePad_DrawCompleted"/>
   </Frame>
   <Label Text="Save Signature as Byte Array:" FontSize="20" FontAttributes="Bold" FontFamily="OpenSansSemibold"/>
   <Frame>
       <Image x:Name="image" HeightRequest="250"/>
   </Frame>
</VerticalStackLayout> 

Step 2: Implement the Logic to Convert Signature into a Byte Array

C#

private void SfSignaturePad_DrawCompleted(object sender, EventArgs e)
{
   StreamImageSource streamImageSource = (StreamImageSource)signaturePad.ToImageSource();
   System.Threading.CancellationToken cancellationToken =
   System.Threading.CancellationToken.None;
   Task<Stream> task = streamImageSource.Stream(cancellationToken);
   Stream stream = task.Result;
   byte[] bytes = new byte[stream.Length];
   stream.Read(bytes, 0, bytes.Length);
   MemoryStream memoryStream = new MemoryStream(bytes);
   image.Source = ImageSource.FromStream(() => memoryStream);
} 

Output:

SignaturePad

Download the complete sample in GitHub

Conclusion
Hope you enjoyed learning about how to save a signature as a byte array in the .NET MAUI SignaturePad.

You can refer to our .NET MAUI SignaturePad’s feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI SignaturePad documentation to understand how to present and manipulate data.

For current customers, you can check out our .NET MAUI components from the License and downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI SignaturePad and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct - Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied