1
votes

Signature pad sending empty

I'm using a Signature Pad, and Canvas by SkiaSharp, but when I sending after drawing by user and encode to base 64, on server only shows an empty canvas

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

Method to send on Services... 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;
        }
    }

END REQUEST...

            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();
            }

The image is empty, is decoded OK and loaded in folder path.

1

1 Answers

0
votes

According to your description, you want to get image from signature pad, and converting it into base 64, I do one simple that you can take a look,just cast your imagestream to memorystream

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