1

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.

Ajbeem
  • 11
  • 1

1 Answers1

0

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);
        }
    }
Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • Hi Cherry Bu, look, I'm try the code you send me, but not succesful, we dessert about that, and, better try on Xcode Swift, but the problem now it's to implement the same thing using a UIImage, early I`m publish the code if you want to contribute, tank's for all – Ajbeem Jul 04 '19 at 15:57