因此,我正在使用 SignaturePad.PCL nuget 包,您可以从插件中恢复流,该插件采用绘制点并创建图像。然后,我将该图像作为 base 64 字符串传递给 Web 服务,并将其显示在 Web 应用程序中。好吧,我发现我能够像这样转换为 base 64 字符串
//This works on android but not iOS
string base64Str = Convert.ToBase64String(((MemoryStream) theStream).ToArray());
//Works on iOS but not android
string base64Str = Convert.ToBase64String(StreamConvert(theStream));
private byte[] StreamConvert(Stream stream){
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
return ms.ToArray();
}
}
//For both I use this, unless someone else can figure out a cross platform solution
string base64Str = Convert.ToBase64String(Device.OS == TargetPlatform.Android ? ((MemoryStream) theStream).ToArray() : StreamConvert(theStream));
有谁知道为什么有区别?