I want to retrieve the signature from an SfSignaturePad on every stroke (as part of validation). I found the sample Saving Result of Signature Pad which, however, uses a call to the SfSignaturePad.Save() method which in its turn clears the pad. I am looking for a good solution how to read the signature image and leave it on the pad.
By browsing through the SfSignaturePad code I found a workaround (shown below) that uses a call to the private method SfSignaturePad.GetImage() but this is not nice as the internals of the pad may change.
Is there a publicly available method to get the image without cleaning the pad and without depending on private methods?
My workaround:
var methodInfo = this.signature.GetType().GetMethod("GetImage", BindingFlags.Instance | BindingFlags.NonPublic);
methodInfo?.Invoke(this.signature, Array.Empty<object>());
if (this.signature.ImageSource is StreamImageSource streamImageSource)
{
var stream = await streamImageSource.Stream(CancellationToken.None);
var bytes = new byte[stream.Length];
await stream.ReadAsync(bytes, 0, bytes.Length);
var imageSource = ImageSource.FromStream(() => stream);
await App.Current.MainPage.DisplayAlert("Length", bytes.Length.ToString(), "cancel");
}
Hi Vladimir,
Query: Is there a publicly available method to get the image without cleaning the pad and without depending on private methods?
Apart from SfSignaturePad.Save() Currently, we don't have any publicly available method for saving the Signature from the Pad. As of now, If you are comfortable with a workaround you can use it. We consider this query for the improvement of the SfSignaturePad. Please let us know if you need any other details.
Regards,
Vijayakumar V
Hi Vijayakumar
Thank you for the update. We think that having such a method is quite useful to be able to check and get the content without having to clear the pad. If you add a public method, please update this thread. Thank you.
Vladimir
Hi Vladimir,
Thanks for the update. We will update you once the public method has been implemented. We appreciate your patience until then.
Regards,
Ruba Shanmugam
Can I be notified when this has been implemented as well please?
One point for Vladimir is that if the SignaturePad doesn't have an image the invoke will result in a TargetInvocationException so I wrap that call in a Try Catch block.
One other thing to consider when implementing this SyncFusion, is that when the SignaturePad is instantiated the image is null (as per my previous comment), but when the Clear method is called, it is set with an empty ImageSource(?) so I can no longer check if there are no bytes in the image to determine if someone has signed in it. I've had to similarly expose the private touchPoints field to see if there is anything in there to determine whether the signature is blank or not.
Hi Craig,
We have created a feature request for saving/reading the signature image without clearing it on the SfSignaturePad.
Feedback link: https://www.syncfusion.com/feedback/39694/provide-support-for-saving-or-reading-the-signature-without-clearing-it-on-the-pad
Please cast your vote to make it count. We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we have committed to already planned work. So, this feature will be available in any of our upcoming releases.
If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal. We will share the release details in the feedback itself.
Regards,
Vijayakumar V