As stated, how should we properly save a captured signature using SignaturePad component to a SQL Server database? Well it should be easy, considering the GetImage(false) method used by the component returns a Bitmap and later on compress the Bitmap into a JPEG and into an array byte using a Stream. The byte array should then be saved directly to the SQL Server database; however, the problem with this approach is that when you retrieve the image from the database, the image is all black. It's like the strokes were never captured, funny thing though is that the background color of the SignaturePad was set to White and the stroke color is Black.
Xamarin.Android Button OnClick Event Handler
var signature = this.SignatureView.GetImage(false); // This returns the Bitmap from SignaturePad.
var imageData = this.ImageToByteArray(signature); // This converts the Bitmap to byte[].
var result = this.SaveDataAsync(imageData); // Save the byte[] to the database.
Xamarin.Android Extension Method
private byte[] ImageToByteArray(Bitmap image)
{
if (image == null) return null;
byte[] result;
using (var stream = new MemoryStream())
{
image.Compress(CompressFormat.Jpeg, 100, stream);
result = stream.ToArray();
stream.Flush();
}
return result;
}
This is the same approach we did on iOS, but doesn't work on Android. Any ideas or working solution would be very much appreciated.
Thanks!
Copied from Xamarin Forum - Components Section