使用的插件: Xamarin.Controls.SignaturePade.Forms(3.0.0)
在iOS上工作正常,但在Android中会引发ObjectDisposedException
try
{
Stream img = await padView.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Png);//.GetImage(ImageFormatType.Png);
ImageSource imgSource = ImageSource.FromStream(() => img);
var memoryStream = new MemoryStream();
long pos = Device.RuntimePlatform == Device.Android ? 0 : img.Position;
img.CopyTo(memoryStream);
byte[] imageArray = memoryStream.ToArray();
ProfileViewModel.SignatureBase64 = Convert.ToBase64String(imageArray);
DigitalSignaturePageViewModel.SignatureBase64 = Convert.ToBase64String(imageArray);
img.Position = pos;
GetSignature.Invoke(this, imgSource);
}
catch (ObjectDisposedException ex)
{
Console.Write(ex.StackTrace);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
答案 0 :(得分:1)
我已经使用padView获得了同样的异常。用图像完成所有工作后,我已经清除了SignaturePad。我做过像padView?.Clear();可能会有所帮助。