Search code examples
c#jsignature

I can't restore the original image from a Base30 text jSignature representation


I am trying to implement the jSignature library in my application but I can't make it work, the actual problem is trying to recreate the original image from the base30 text. In order to do it I draw something in their demo, take the base30 text and paste it in my app but the generated image has almost nothing to do with the original one. The code of my sample app is this:

    private void BtnConvertToSVG_Click(object sender, EventArgs e)
    {
        convertFromBase30();
    }

    private void convertFromBase30()
    {
        try
        {
            jSignature.Tools.Base30Converter Base30 = new jSignature.Tools.Base30Converter();
            String base30Text = tbBase30Text.Text.ToString();
            int[][][] arrBase30 = Base30.Base30ToNative(base30Text);
            String strSVG = jSignature.Tools.SVGConverter.ToSVG(arrBase30);
            tbSVG.Text = strSVG;
            MemoryStream s = new MemoryStream(Encoding.ASCII.GetBytes(strSVG));
            SvgDocument mySVG = SvgDocument.Open<SvgDocument>(s, null);
            var tempStream = new System.IO.MemoryStream();
            mySVG.Draw().Save(tempStream, System.Drawing.Imaging.ImageFormat.Png);
            System.Drawing.Image img = System.Drawing.Image.FromStream(tempStream);
            pbImage.Image = img;
        }
        catch (Exception ex)
        {
            MessageBox.Show(String.Format("{0}", ex.Message));
        }
    }

It is a Windows Forms application with two TextBox:

  • tbBase30Text: Here I introduce the base30 text
  • tbSVG: Where the app writes the SVG image code

A Button (btnConvertToSVG) and a PictureBox where I print the generated image. It makes use of the libraries included in the jSignature project

If I draw an SO image in their demo it gives me the next result Original signature

Pasting the base30 code in my application gives me the next result:

Result signature

I don't understand why but the only common thing between both signatures are the number of lines.

There are some forks of this library, the brinley's one (last updated) and the willowsystems's are which I tried with no success.


Solution

  • I finally solved it thanks to another SO question talking about the same problem. The error was in the library to convert to SVG included in the jSignature project.

    All the String.Format ignore the Culture when converting the String adding errors to the final result, you can fix it by adding CultureInfo.InvariantCulture to all of them at the beginning

    String.Format(CultureInfo.InvariantCulture, ...)