1

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

Domingo
  • 41
  • 1
  • 3
  • What does "doesn't work" mean? – Cheesebaron Aug 08 '15 at 15:09
  • My apologies if I wasn't clear enough. Doesn't work means any attempt to save the Signature captured by using 'this.GetImage(false)' method and into SQL Server database, the image returns all black when retrieved. On iOS, we're able to retrieve the same image as captured from the SignaturePad component using the same approach as stated from my original post. Of course the codes will be slightly different but the results should be the same with that of Android's. Well, at least that's what we expect it to be... I could be wrong; thus, this question has been posted. – Domingo Aug 11 '15 at 15:03

1 Answers1

0

Okay, I think I found a solution to this issue, which was described in this thread Signature Pad for Xamarin.Forms. I am not sure why we need to specify the colors within the GetImage() method, while the properties for the Stroke and Background colors has already been specified. Well, I guess the colors needed to draw the image is not the same with that of the properties.

Domingo
  • 41
  • 1
  • 3