Getting Signature Image from Signature Pad without Clearing It

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");

}


5 Replies

VV Vijayakumar Viswanathan Syncfusion Team August 15, 2022 12:23 PM UTC

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



VP Vladimir Petrov August 15, 2022 12:26 PM UTC

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 



RS Ruba Shanmugam Syncfusion Team August 16, 2022 08:51 AM UTC

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



CP Craig Poxon November 14, 2022 05:44 PM UTC

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.



VV Vijayakumar Viswanathan Syncfusion Team December 9, 2022 12:40 PM UTC

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


Loader.
Up arrow icon