Articles in this section
Category / Section

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

2 mins read

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

Step 1: Initialize the Signature Pad 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 from GitHub.

Conclusion
I hope you enjoyed learning how to save a signature as a byte array in the .NET MAUI Signature Pad.

For more features, visit our .NET MAUI Signature Pad’s feature tour and explore the .NET MAUI Signature Pad documentation.

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

If you have any queries or require clarification, 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