0

I need some help about .net method to convert jsignature exported data. I have an Android app sending base30 compressed data (for example "quaok1C2S3Q3W3A2A2I1Uk1y800Z6c1y1y1W2G2w2C2u1O1M1wie800Y2ccm1A1C1Q1S1U2G2y2M1O1u1y4424681y1C1Q2M2Q2w2A2woce_dC200Z2688408ccoeiamiga800000Y48gic1u1ucmaes866402000Z224420000000000002") and a .Net web service (rest) receving data in order to save them to database and do some business. At the moment I'm experimenting some problem in converting data from base30 to image. As example, I'm referring to the SignatureDataConversion_dotNet code in the "extras" folder of the jsignature zip (https://github.com/willowsystems/jSignature) in order to do the conversion and manage data. But something is not working for me...or, maybe, I've not completely understood how to manage base30 signature in .Net

This is a piece of the code I'm using:

Base30Converter conv = new Base30Converter();
int[][][] bytearray = conv.GetData(base30_string_from_app);
string actual = jSignature.Tools.SVGConverter.ToSVG(bytearray);
var byteArray = Encoding.ASCII.GetBytes(actual);
using (var stream = new MemoryStream(byteArray))
{
    var svgDocument = SvgDocument.Open(stream);
    var bitmap = svgDocument.Draw();
    bitmap.Save("D:\prova.png", ImageFormat.Png);
}

But the image I get seems to be a "partion" of the whole signature sent, with only some strokes. I've also checked the string I am manipulating: it is the same of what the app is sending. As confirmation of this I succed in importing it on a html canvas, using jSignature "setData" method.

Thanks in advance for any help


As another example of the probable issue with the base30 conversion to svg in .Net, here we have the svg conversion of a signature exportet from http://willowsystems.github.io/jSignature/#/demo/

[svg] [https://] dl.dropboxusercontent.com/u/77767500/SVG_from_jsignature_site.svg

this is the base 30 conversion of the same sign:

7yf1Ul1H4232121Z4577dabdllhhne1uf6423Y2587ddn1v1x1G1A1D1wpordd8431Z1338ffppkm1v1Db964210Y158b46ffgqkhqfef8673523_3EZ2519332455410Y315329745ba9me5343421200100000Z22345233345323311000Y142853746743121000Z10041112224332_jVZ746ba553200Y12368cabceb8a74200Z234a4ebcebfdbc65Y68afjdjd9f864334_4SZ110000Y3368745322000000Z1123355584323113000000Y31Z101101201001221

Trying to convert it using

Base30Converter conv = new Base30Converter();
int[][][] bytearray = conv.GetData(stream_to_convert);
string actual = jSignature.Tools.SVGConverter.ToSVG(bytearray);

i get:

[https://] dl.dropboxusercontent.com/u/77767500/SVG_from_jsignature_lib.svg

As you can see the two "svg" conversion seems to be different. So, maybe, there is something not working properly in the jSignature.Tools for .Net ...

Simply Leo
  • 1
  • 1
  • 4

2 Answers2

4

It took me a lot of trial and error with the .NET tools included in the jSignature package, but here's how I eventually got it to generate a PNG from a base30 jSignature string. I'm using VB .NET and returning a System.Drawing.Image (which you can output however you want):

Public Function GetSignaturePNG() As System.Drawing.Image
    'jSignature conversion from base30 to SVG            
    Dim base30Converter As New jSignature.Tools.Base30Converter()
    Dim arrBase30Data As Integer()()() = base30Converter.GetData(Me.SigBase30) 'our original base30 string
    Dim strSVG As String = jSignature.Tools.SVGConverter.ToSVG(arrBase30Data)

    'first convert it to SVG
    Dim mySVG As SvgDocument
    Dim newStream As New System.IO.MemoryStream(System.Text.ASCIIEncoding.[Default].GetBytes(strSVG))
    mySVG = SvgDocument.Open(newStream, Nothing)       

    'then convert it to PNG
    Dim tempStream As New System.IO.MemoryStream()
    mySVG.Draw().Save(tempStream, System.Drawing.Imaging.ImageFormat.Png)
    Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(tempStream)

    Return img
End Function

Update 6.20.2014: Leo, I was able to successfully export your base30 signature string (listed in your original question) as both SVG and PNG. And I got the entire "leo" signature, not just the few broken strokes. So I'm not sure what we're doing differently. Are you sure you're passing in the entire base30 string to the function?

Haywain
  • 88
  • 4
2

The SVGConverter class uses string.Format to output decimals to the string. If your current culture is e.g. set to German, it will output fractions with a comma instead of points. So, add CultureInfo.InvariantCulture as the first argument to each String.Format in that class to make sure the SVG output is formatted with decimal points.