dcsimg
Results 1 to 12 of 12
  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2016
    Posts
    16

    Question How can I convert an electronic signature into a printable image?

    How can I convert an electronic signature (string) into a printable image?

    The signature response data is a string of up to 2048 characters returned as a series of "strokes".
    Within each stroke is a series of X,Y coordinate points.
    X and Y coordinates are separated by a comma and end with a colon.
    The first point of a stroke is always a "move to" position.
    All subsequent points within a stroke are "draw to" positions.
    The "end stroke point" is simply #,#: which is followed by the first point of the next stroke.


    <?xml version="1.0"?>
    <RStream>
    <CmdResponse>
    <ResponseOrigin>Client</ResponseOrigin>
    <DSIXReturnCode>000000</DSIXReturnCode>
    <CmdStatus>Success</CmdStatus>
    <TextResponse>Success</TextResponse>
    <SequenceNo>0010010010</SequenceNo>
    <UserTrace></UserTrace>
    </CmdResponse>
    <Signature>11,29:12,29:11,29:11,28:10,28:11,28:11,29:12,29:13,30:14,30:15,31:16,32:17,32:18,32:19,33 :20,33:21,34:22,34:24,35:25,35:27,36:28,36:30,37:32,38:34,38:36,39:37,39:39,40:42,41:44,41:46,42:48, 43:50,43:52,44:54,45:56,46:58,46:60,47:62,48:64,48:66,49:68,50:69,50:71,51:73,51:74,51:76,51:77,51:7 9,52:80,52:82,52:83,52:85,51:86,51:87,51:88,51:89,51:90,51:91,51:92,51:93,51:92,50:92,49:93,48:93,47 :93,46:#,#:163,50:162,50:161,50:160,51:159,51:159,52:158,52:158,53:157,53:158,53:158,52:159,51:160,5 0:162,49:164,47:167,45:169,42:172,39:176,37:179,34:183,31:187,28:190,25:194,23:197,20:200,18:203,16: 206,15:208,14:210,13:212,12:214,11:215,11:216,10:217,10:218,10:217,10:216,10:216,11:215,11:214,11:21 3,11:212,11:212,10:211,10:#,#:</Signature>
    <SignMaximumX>228</SignMaximumX>
    <SignMaximumY>63</SignMaximumY>
    </RStream>
    Attached Images Attached Images

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,410

    Re: How can I convert an electronic signature into a printable image?

    Which part(s) are you having problems with?
    Parsing the lines from the file?
    Parsing the strings for the coordinates?
    Drawing the coordinates?
    Saving the image to a file?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2016
    Posts
    16

    Re: How can I convert an electronic signature into a printable image?

    Quote Originally Posted by passel View Post
    Which part(s) are you having problems with?
    Parsing the lines from the file?
    Parsing the strings for the coordinates?
    Drawing the coordinates?
    Saving the image to a file?
    Thank you very much for your quick reply.
    I parsed the string from C# code but how to:
    Drawing the coordinates, and save in memory to print.
    Saving the image to a file? (save to test)


    Code:
    Sub ConvertSignatureDataToImage(Optional SignatureData As String)
        On Error Resume Next
        Dim Signature As String
        Dim X As String
        Dim Y As String
        Dim keepX As String
        Dim keepY As String
        Dim SignMaximumX As Integer
        Dim SignMaximumY As Integer
        Dim stringOfPoints() As String
        Dim beginStroke As Boolean
        
        beginStroke = True
        If IIf(Trim(SignatureData) <> "", Module2.GetXMLElementValue("cmdStatus", SignatureData), "") = "Success" Then
            Signature = Module2.GetXMLElementValue("Signature", SignatureData)
            SignMaximumX = Module2.GetXMLElementValue("SignMaximumX", SignatureData)
            SignMaximumY = Module2.GetXMLElementValue("SignMaximumY", SignatureData)
            
            
            stringOfPoints = Split(Signature, ":")
            For i = 0 To UBound(stringOfPoints)
               If Trim(stringOfPoints(i)) <> "" Then
                  Dim point As String
                  point = stringOfPoints(i).Split(",")
                  X = point(0)
                  Y = point(1)
                  If (X = "#" And Y = "#") Then
                      beginStroke = True
                  Else
                      If beginStroke Then
                          beginStroke = False
                      Else
                           ' DRAW HERE
                      End If
                  End If
                  keepX = X
                  keepY = Y
               End If
            Next
        End If
    End Sub
    Last edited by oxixo; Feb 9th, 2018 at 12:37 PM.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,410

    Re: How can I convert an electronic signature into a printable image?

    Well, the code looks like its along the lines of what I tested earlier.
    I'll post my code and let you figure out how to adapt it for your purposes.
    I used a picturebox to draw in, and didn't use the min/max values which could be used to size the picturebox if desired.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      Dim s As String
      s = "<Signature>11,29:12,29:11,29:11,28:10,28:11,28:11,29:12,29:13,30:14,30:15,31:16,32:17,32:18,32:19,33:20,33:21,34:22,34:24,35:25,35:27,36:28,36:30,37:32,38:34,38:36,39:37,39:39,40:42,41:44,41:46,42:48,43:50,43:52,44:54,45:56,46:58,46:60,47:62,48:64,48:66,49:68,50:69,50:71,51:73,51:74,51:76,51:77,51:79,52:80,52:82,52:83,52:85,51:86,51:87,51:88,51:89,51:90,51:91,51:92,51:93,51:92,50:92,49:93,48:93,47:93,46:#,#:163,50:162,50:161,50:160,51:159,51:159,52:158,52:158,53:157,53:158,53:158,52:159,51:160,50:162,49:164,47:167,45:169,42:172,39:176,37:179,34:183,31:187,28:190,25:194,23:197,20:200,18:203,16:206,15:208,14:210,13:212,12:214,11:215,11:216,10:217,10:218,10:217,10:216,10:216,11:215,11:214,11:213,11:212,11:212,10:211,10:#,#:</Signature>"
     ' s = "<Signature>50,40:48,41:45,42:43,43:42,44:40,45:38,46:36,47:34,48:32,49:30,49:28,50:23,50:21,49:19,49:17,48:16,47:14,45:13,44:12,42:11,40:10,37:10,32:11,31:12,29:14,27:17,27:18,26:19,27:21,27:22,28:23,29:25,30:26,31:28,33:29,35:30,37:32,39:33,42:34,45:34,49:35,52:36,56:36,68:35,77:34,81:33,85:#,#:10,85:11,80:13,76:15,72:17,69:19,66:22,63:24,61:26,59:29,58:31,57:34,56:38,56:40,57:44,58:45,59:47,60:48,61:49,62:50,64:51,66:#,#:</Signature>"
      s = Replace(s, "<Signature>", " ")
      s = Replace(s, "</Signature>", " ")
      If Right$(s, 1) = ":" Then Mid$(s, Len(s), 1) = " "
      
      Picture1.ScaleMode = vbPixels
      Picture1.AutoRedraw = True
      Picture1.Cls
      
      Dim sa() As String
      sa = Split(s, ":")
      
      Dim i As Integer
      Dim drawing As Boolean
      Dim coord() As String
      Dim x As Single, y As Single
      
      For i = 0 To UBound(sa)
        If sa(i) = "#,#" Then
          drawing = False
        Else
          If Len(sa(i)) > 3 Then
            coord = Split(sa(i), ",")
            x = Val(coord(0))
            y = Val(coord(1))
            If drawing Then
              Picture1.Line -(Val(coord(0)), Val(coord(1)))
            Else
              Picture1.PSet (Val(coord(0)), Val(coord(1)))
              drawing = True
            End If
          End If
        End If
      Next
      SavePicture Picture1.Image, "C:\c\signature.bmp"
    End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2016
    Posts
    16

    Re: How can I convert an electronic signature into a printable image?

    Thank you very much passel. I draw test 2 lines. It is correct.

    How to draw signature in memory which no need use PictureBox.
    Because after I receive "XML signature", I will parse and print the signature to Receipt.
    Last edited by oxixo; Feb 9th, 2018 at 02:19 PM.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,410

    Re: How can I convert an electronic signature into a printable image?

    Well, the Printer Object supports drawing, i.e. the Printer.Pset and Printer.Line commands, so you shouldn't have to draw the signature in memory, you could just draw it on the printer.
    You probably need an X,Y offset to add to the points to position the signature where you want, and perhaps need to multiply the coordinates by a scaling factor to size the signature to the size you want.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2016
    Posts
    16

    Re: How can I convert an electronic signature into a printable image?

    Quote Originally Posted by passel View Post
    Well, the Printer Object supports drawing, i.e. the Printer.Pset and Printer.Line commands, so you shouldn't have to draw the signature in memory, you could just draw it on the printer.
    You probably need an X,Y offset to add to the points to position the signature where you want, and perhaps need to multiply the coordinates by a scaling factor to size the signature to the size you want.
    Hi passel , thanks for your reply.
    How to create image which don't need to use PictureBox?
    I want to save image to C driver.

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,410

    Re: How can I convert an electronic signature into a printable image?

    I think you would have to use API methods to draw in a bitmap and I haven't done that in VB6 and earlier.
    I was saying you could draw directly to a printer, but if you want to save an image to a drive then I would probably just use a hidden Picturebox, with Autoredraw set, to draw in and then use savePicture to save the image to disk. Of course the image is a bitmap at that point, not the most efficient way to store the image.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,809

    Re: How can I convert an electronic signature into a printable image?

    Everything needed has been discussed in this forum and in many cases reusable code has been posted to the CodeBank. What isn't exactly what you want probably only needs minor tweaking.

    Here is an example that draws the signature (hopefully it isn't upside down!), then plops it into an Image control and centers that near the bottom of the Form, draws it scaled with transparency onto the Form (simulating printing), and saves the original to disk in PNG format. There is code there to load a PNG into a StdPicture object as well.

    Name:  sshot.png
Views: 64
Size:  3.6 KB

    You can do almost all of this with VB6 Printer and PictureBox drawing methods of course. But my Drawing class offers an alternative that you can add more features to as required.


    Ok, I noticed that I had done an aggressive "replace" and sort of messed things up within Drawing.cls so that has been fixed.

    Then I went back in and added a few enhancements such as halftone StretchBlt() to help smooth out jaggies and added a RenderTo() method that can do simple maskcolor-transparency rendering so you don't have to call TransParentBlt() explicitly in your client code.

    That at least cleans up my mess and gives a somewhat better result. To get much better smoothing you'd probably have to resort to GDI+ calls or some library that wraps GDI+.
    Attached Files Attached Files
    Last edited by dilettante; Mar 6th, 2018 at 11:52 AM.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,809

    Re: How can I convert an electronic signature into a printable image?

    Of course I still have no idea whether I might have the "signature" upside-down, backwards, or scrambled into garbage.

    Nobody is laughing hard yet though, at least not to my face here! I'll take that as a positive for now.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,809

    Re: How can I convert an electronic signature into a printable image?

    Oh yeah... I changed the BackColor from the yellowish hue to white.

    That's because if you try to use halftone smoothing like this then when you render using a "transparent color" you can end up with background-colorish fringes in your result and whitish fringes are normally less undesirable. Probably especially when printing, which I presume was the actual result desired anyway.

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,593

    Re: How can I convert an electronic signature into a printable image?

    I'd convert these Signature-Polygon-Point-Definitions into a resolution-independent vector-format -
    easier to render from such a format to any destination (Screen or PDF-file) with the proper scale-factor.

    The DemoCode below is using the Response-XML-example, as described in your PDF-document from this URL:
    http://vbrichclient.com/Downloads/SigResponse.xml

    ...and it creates an appropriate *.svg File from that input (using BSpline-Interpolation, to make it look a bit nicer) - the result being this one:
    http://vbrichclient.com/Downloads/Signature_295x95.svg

    The Form-code below is using the vbRichClient5-framework to accomplish that (needs an appropriate Project-reference first):
    Code:
    Option Explicit
     
    Private Sub Form_Load()
      Dim sSig As String, SigW As Double, SigH As Double
      ParseXML XMLFromURL("http://vbRichClient.com/Downloads/SigResponse.xml"), sSig, SigW, SigH
      
      Dim FileNameSvg As String
          FileNameSvg = "c:\temp\Signature_" & SigW & "x" & SigH & ".svg"
      CreateSVG FileNameSvg, sSig, SigW, SigH
     
      Const SvgZoom = 2 '<- read the SVG we just wrote (using the SvgZoom-Factor as given)
      Set Picture = Cairo.ImageList.AddImage("Svg", FileNameSvg, SvgZoom * SigW, SvgZoom * SigH).Picture
    End Sub
    
    'two helper-routines, 1) to load the XML via http and 2) to parse the returned XML-string for the 3 relevant members
    Private Function XMLFromURL(URL As String) As String
      With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", URL, False: .Send
        XMLFromURL = .ResponseText
      End With
    End Function
    Private Sub ParseXML(sXML As String, sSig As String, SigW As Double, SigH As Double)
      Dim DOM As cSimpleDOM, Elm As cElement
      Set DOM = New_c.SimpleDOM(sXML)
      For Each Elm In DOM.Elements
        Select Case Elm.TagName
          Case "Signature":    sSig = Replace(Replace(Replace(Elm.Text, " ", ""), vbCr, ""), vbLf, "")
          Case "SignMaximumX": SigW = Val(Elm.Text)
          Case "SignMaximumY": SigH = Val(Elm.Text)
        End Select
      Next
    End Sub
    
    'and two drawing-related helper-routines, here for cairo-SVG-rendering
    Private Sub CreateSVG(FileName As String, sSig As String, SigW As Double, SigH As Double)
      With Cairo.CreateSurface(SigW, SigH, SVGSurface) 'create an SVG-Surface in the right size
        RenderTo .CreateContext, sSig, True 'call a SubRoutine, to parse and render the PolyPoints in sSig
        .WriteContentToSVGFile FileName
      End With
    End Sub
    Private Sub RenderTo(CC As cCairoContext, sSig As String, ByVal SplineInterpol As Boolean)
      CC.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
      CC.SetLineCap CAIRO_LINE_CAP_ROUND
      
      Dim sPoly, sPoint, Poly As cArrayList
      For Each sPoly In Split(sSig, ":#,#:")
        Set Poly = New_c.ArrayList(vbDouble)
        For Each sPoint In Split(sPoly, ":")
          If InStr(sPoint, ",") Then
            Poly.Add Val(Split(sPoint, ",")(0))
            Poly.Add Val(Split(sPoint, ",")(1))
          End If
        Next
        If Poly.Count Then
          CC.PolygonPtr Poly.DataPtr, Poly.Count \ 2, , IIf(SplineInterpol, splNormal, splNone), True, Not SplineInterpol
          CC.Stroke False, Cairo.CreateSolidPatternLng(vbBlack)
        End If
      Next
    End Sub
    
    Private Sub Form_Terminate() 'the usual RC5-cleanup-routine, called on App-Shutdown
      If Forms.Count = 0 Then New_c.CleanupRichClientDll
    End Sub
    HTH

    Olaf

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.