I m using the CommunityToolkit.Maui.Views.DrawingView to capture a customer signature. Once they have finished i hide the DrawingView and display it as in image, so as to not interfere with scrolling. The code used to switch between the editor and the image is:
private async void ElEditSignatureButton_Clicked(object sender, EventArgs e)
{
if (!EditingSignature)
{
ElCustomerSignatureImage.IsVisible = false;
ElCustomerSignatureDraw.IsVisible = true;
ElEditSignatureButton.Source = ImageSource.FromFile("tick.png");
EditingSignature = true;
}
else
{
if (ElCustomerSignatureDraw.Lines.Count > 0)
{
Stream stream = await ElCustomerSignatureDraw.GetImageStream(ElCustomerSignatureImage.Width, ElCustomerSignatureImage.Height);
byte[] bytes = new byte[stream.Length];
stream.Write(bytes, 0, bytes.Length);
SignatureImage = bytes;
ElCustomerSignatureImage.Source = ImageSource.FromStream(() => new MemoryStream(bytes));
ElCustomerSignatureDraw.IsVisible = false;
ElCustomerSignatureImage.IsVisible = true;
ElEditSignatureButton.Source = ImageSource.FromFile("pencil.png");
EditingSignature = false;
}
else
{
await DisplayAlert("Customer Report", "Signature Required", "Ok");
}
}
}
然而,在这样做时,没有显示这种形象。
If i change it to remove the convertion to byte[] (for use later when submitting) the image works:
Stream stream = await ElCustomerSignatureDraw.GetImageStream(ElCustomerSignatureImage.Width, ElCustomerSignatureImage.Height);
ElCustomerSignatureImage.Source = ImageSource.FromStream(() => stream);
在撰写本报告时,我发现:
Stream stream = await ElCustomerSignatureDraw.GetImageStream(ElCustomerSignatureImage.Width, ElCustomerSignatureImage.Height);
ElCustomerSignatureImage.Source = ImageSource.FromStream(() => stream);
Stream stream2 = await ElCustomerSignatureDraw.GetImageStream(ElCustomerSignatureImage.Width, ElCustomerSignatureImage.Height);
byte[] bytes = new byte[stream2.Length];
stream2.Write(bytes, 0, bytes.Length);
SignatureImage = bytes;
Does anyone know why the first example doesn t work? I mean a stream of bytes should just be a stream of bytes regardless of it s method of creation.
EDIT: 矫正,即说行之有效的最后选择, by变具有正确的长度,但数据是所有0, 认为也是第一个例子的问题。