How to draw a signature and save it to disc as a Bitmap?

前端 未结 3 1310
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 23:46

I\'m trying to do a signature capture program and save the customer signature to a PNG or BMP format. I have the Picturebox code working great and

3条回答
  •  -上瘾入骨i
    2021-01-16 00:09

    When wanting to save as BMP, the background needs to be white because BMP doesnt support Transparency. With that being said, I have added these 2 lines above the DrawPath call.

    Dim Brsh As SolidBrush = New SolidBrush(Color.White)
    g.FillRectangle(Brsh, 0, 0, pBoxSignature.Width, pBoxSignature.Height)
    g.DrawPath(signaturePen, gPath)
    

    BUT, Now I am no longer able to pickup my pen stroke otherwise all previous strokes get erased/cleared. (Meaning first and last names need to be written without pickup up pen) Could someone with more knowledge on images perhaps see a reason for this and point me in the direction of a solution?

    UPDATE: Working Code

    Here is the code:

    Using imgSignature As Bitmap = New Bitmap(pBoxSignature.Width, pBoxSignature.Height, PixelFormat.Format32bppRgb)
        Using g As Graphics = Graphics.FromImage(imgSignature)
            g.FillRectangle(Brsh, 0, 0, pBoxSignature.Width, pBoxSignature.Height)
            Call DrawSignature(g)
        End Using
        imgSignature.Save(signaturePath, ImageFormat.Bmp)
        pBoxSavedSignature.Image = New Bitmap(imgSignature)
    End Using
    

提交回复
热议问题