1

签名板发送空

我使用的是签名板和 SkiaSharp 的画布,但是当我在用户绘制后发送并编码到 base 64 时,服务器上只显示一个空画布

   async void OnSaveButtonClicked(object sender, EventArgs args)
    {
        using (SKImage image = SKImage.FromBitmap(saveBitmap))
        {
            try
            {
                SKData data = image.Encode(SKEncodedImageFormat.Png, 100);
                var bytesImg = data.ToArray();
                string imageBase64 = Convert.ToBase64String(bytesImg);
                var respuesta = await this.ApiService.PostSignature(
                this.url,
                this.Id,
                imageBase64
                );

在服务上发送的方法... public async Task PostSignature(string urlBase, string folio, string imageBase64) { try { var client = new HttpClient(); var response = await client.PostAsync(urlBase, new StringContent(string.Format("idReporte={0}&imgFirma={1}", folio, imageEncoded), Encoding.UTF8, "application/x-www-form-urlencoded" ));

            if (!response.IsSuccessStatusCode)
            {
                return response.ToString();
            }
            else
            {
                var result = await response.Content.ReadAsStringAsync();
                return result;
            }

        }
        catch
        {
            return null;
        }
    }

结束请求...

            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Image Is not Send, error: " + ex.Message,
                    "OK"

                    );
            }
            finally
            {
                completedPaths.Clear();
                inProgressPaths.Clear();
                UpdateBitmap();
                canvasView.InvalidateSurface();
            }

图像为空,解码正常并加载到文件夹路径中。

4

1 回答 1

0

根据您的描述,您想从签名板获取图像,并将其转换为base 64,我做了一个简单的,您可以看一下,只需将您的图像流转换为内存流

  <StackLayout>
        <forms:SignaturePadView
            x:Name="signaturepad"
            BackgroundColor="Black"
            HeightRequest="350"
            StrokeColor="White"
            StrokeWidth="3"
            WidthRequest="250" />

        <Button
            x:Name="save"
            Clicked="Save_Clicked"
            HeightRequest="50"
            Text="save"
            WidthRequest="200" />
    </StackLayout>



 private async void Save_Clicked(object sender, EventArgs e)
    {
        string base64String;
        using (var memoryStream = new MemoryStream())
        {
            var signature = await signaturepad.GetImageStreamAsync(SignatureImageFormat.Png);
            signature.CopyTo(memoryStream);
            var byteArray = memoryStream.ToArray();
            base64String = Convert.ToBase64String(byteArray);
        }
    }
于 2019-06-18T03:02:43.713 回答