1

After downloading xamarin.signaturePad sample i just want to get image from signature pad to memory stream and show on my imageview. here is my code and its working fine on iOS but on android its showing empty stream

var image = await padView.GetImageStreamAsync(SignatureImageFormat.Png);
var stream = new MemoryStream();
image.CopyToAsync(stream);
var imageByteArray= stream.ToArray();
img_result.Source = ImageSource.FromStream(() => newMemoryStream(imageByteArray));
umair
  • 607
  • 4
  • 18

1 Answers1

2

Just cast your imagestream to memorystream. It should be valid

var imageStream = await padView.GetImageStreamAsync(SignatureImageFormat.Png);

// this is actually memory-stream so convertible to it
var mstream = (MemoryStream)imageStream;

//Unfortunately above mstream is not valid until you take it as byte array
mstream = new MemoryStream(mstream.ToArray());

//Now you can
img_result.Source = ImageSource.FromStream(()=>mstream);
Sami
  • 8,168
  • 9
  • 66
  • 99
  • I'm getting an Invalid Cast Exception on iOS, so I was switching back to ``CopyTo()``, which seems to work on Android (v3.0.0 of the SignaturePad). – thomiel Sep 09 '22 at 14:40