0

I have a PictureBox, which I am using as a "Signature pad". The size is 475,175...If the user signs in a small area, I would like to only save the portion that has a signature mark. I am not sure where to begin. Any help would greatly be appreciated.

Private Sub btnSaveSignature_Click(sender As Object, e As EventArgs) Handles btnSaveSignature.Click
    Dim signatureFileName = txtSignatureFileName.Text.Trim()
    Dim signaturePath As String = Path.Combine(Application.StartupPath, txtSignatureFileName.Text & ".bmp")

    If String.IsNullOrEmpty(signatureFileName) Then Return
    If currentCurve < 0 OrElse signatureObject(currentCurve).Count = 0 Then Return
    Using imgSignature As Bitmap = New Bitmap(pBoxSignature.Width, pBoxSignature.Height, PixelFormat.Format32bppRgb)
        Using g As Graphics = Graphics.FromImage(imgSignature)
            ''BMPs require a White background.  This line provide that.
            g.FillRectangle(Brsh, 0, 0, pBoxSignature.Width, pBoxSignature.Height)
            Call DrawSignature(g)
        End Using

        pBoxSignature.SizeMode = PictureBoxSizeMode.AutoSize
        pBoxSavedSignature.SizeMode = PictureBoxSizeMode.AutoSize

        imgSignature.Save(signaturePath, ImageFormat.Bmp)
        pBoxSavedSignature.Image = New Bitmap(imgSignature)
    End Using
End Sub

The above code is my Save to BMP routine. I would imagine any solution would need to go in this section.

  • Interesting. Maybe knowing what the `DrawSignature(g)` does helps to find a way to achieve that. Just maybe. –  Nov 05 '19 at 05:08
  • Taken from here: [How to draw a signature and save it to disc as Bitmap?](https://stackoverflow.com/a/57084653/7444103). You may have noticed that the code I posted is using a GraphicsPath to hold the signature curves, thus you have all the points that compose the Bezier curves corresponding to the hand movements. The GraphicsPath has a specific size that is returned by `GraphicsPath.GetBounds()`. You can build a bitmap object using these measures (inflated by half the pen size). – Jimi Nov 05 '19 at 05:59
  • Also, since it's composed by a collection of vectors, it can be saved as a Metafile. – Jimi Nov 05 '19 at 06:08
  • Thank you. I am going to give your suggestion a try. I am not that fluent in "graphics", but i'm always up for learning something new. – MrAvgProgrammer Nov 05 '19 at 13:49
  • Jimi, I realize with BMP's you can not have transparent backgrounds, but I am trying to make it white. I was able to make it white but when I display the image on a SAP report it seems to have a grey/pixelated background. But when I open the image in windows it is as white as could be. Any thoughts. – MrAvgProgrammer Nov 05 '19 at 13:53
  • When you draw the Bitmap, in `DrawSignature()` add `g.Clear(Color.White)`. If you have gray-ish halos aroung the curves, set `g.SmoothingMode = SmoothingMode.None`. It will remove part of the anti-aliasing (not all). If the image's background is not white in your report, then the rendering engine of the reporting service is responsible for that. Or you're using some sort of quality reduction (or enhancement) that is not configured correctly. Or the image is converted to another format before it's used. – Jimi Nov 05 '19 at 17:16
  • Thank you Jimi I will try that g.Clear suggestion and see what the results are. Note: I have used a SignoTec Pad in the past which generates a BMP with a white background (using their DLLS) and it loads just fine onto the reports. So I suspect it is something on how my images are being created. – MrAvgProgrammer Nov 05 '19 at 17:47
  • Jimi, thank you for the smoothing mode tip That solved my "grey" background issue I was having. Not being very familiar with Bounds and graphics, might you have a way of simply saving the "Jimi" portion of your signature? I am trying to figure out how to use all the values in the GetBounds(), cant quite figure out the best way yet. – MrAvgProgrammer Nov 05 '19 at 18:51

0 Answers0