I work on a Xamarin.Forms app where I've implemented a signature control with the Syncfusion SfSignaturePad
I would like to send the signature image to an API.
For this, I've converted the ImageSource of the related signature to a byte array like this:
SfSignaturePad signaturePad;
public byte[] SignaturePadImage { get; set; }
private void BtnConvert_Tapped(object sender, EventArgs e)
{
signaturePad.Save();
if (signaturePad.ImageSource != null)
{
StreamImageSource streamImageSource = (StreamImageSource)signaturePad.ImageSource;
System.Threading.CancellationToken cancellationToken =
System.Threading.CancellationToken.None;
Task<Stream> task = streamImageSource.Stream(cancellationToken);
Stream stream = task.Result;
// store bytes
SignaturePadImage = new byte[stream.Length];
stream.Read(SignaturePadImage, 0, SignaturePadImage.Length);
}
}
This allows me to set the byte array as Source of an Image to display the corresponding image.
But when I send the byte array to the API, the image format is not recognized, as it based on a Xamarin.Forms.ImageSource.
So I would like to "convert" my ImageSource to a formated image (as .PNG, .BMP, ...) before to recover the byte array.
What should be the better approach to achieve this?