Hello,
I am still confused about a few things.
Firstly my code for saving the signature that has been captured on the picturebox1.
vb Code:
Code SnippetPrivate Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click Try Dim bmp As New Bitmap(Me.PictureBox1.Image) Using g As Graphics = Graphics.FromImage(bmp) Using pen As Pen = New Pen(Color.Red, 2) For Each pointList As List(Of Point) In strokeCollection If (pointList.Count >= 2) Then g.DrawLines(pen, pointList.ToArray()) End If Next pointList End Using End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub
Here I get an error message on this line: Dim bmp As New Bitmap(Me.PictureBox1.Image). 'The picture.Image is NULL'
My understanding that the picturebox1.Image should be the signature that has been captured on the pictureBox1. And as this has been drawn over, it shouldn't really be null but contain the signature itself. Correct me if I am wrong?
Many thanks for your help.
The rest of the code for my program is below if you need to review.
vb Code:
Code Snippet #Region "Local Variables" Private lastPoint As Point Private strokeCollection As New List(Of List(Of Point)) Private currentStroke As New List(Of Point) #End Region #Region "Constructor" Public Sub New() InitializeComponent() AddHandler PictureBox1.Paint, AddressOf PictureBox1_Paint End Sub #End Region #Region "PictureBox1_Paint Event" Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As PaintEventArgs) For Each pointList As List(Of Point) In strokeCollection If pointList.Count >= 2 Then Using pen As New Pen(Color.Black, 2) e.Graphics.DrawLines(pen, pointList.ToArray()) End Using End If Next End Sub #End Region #Region "Picture box mouse down event" Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown Try Me.lastPoint = New Point(e.X, e.Y) Me.currentStroke = New List(Of Point) Me.strokeCollection.Add(Me.currentStroke) Catch ex As Exception MsgBox(ex.Message) End Try End Sub #End Region #Region "Picture box mouse move event" Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove Dim hDC As IntPtr = GetDC(Me.PictureBox1.Handle) Using g As Graphics = Graphics.FromHdc(hDC) Using pen As Pen = New Pen(Color.Black, 2) g.DrawLine(pen, lastPoint.X, lastPoint.Y, e.X, e.Y) End Using End Using ReleaseDC(Me.PictureBox1.Handle, hDC) Me.lastPoint = New Point(e.X, e.Y) Me.currentStroke.Add(Me.lastPoint) End Sub #End Region #Region "Attributes" <System.Runtime.InteropServices.DllImport("coredll.dll")> _ Private Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr End Function <System.Runtime.InteropServices.DllImport("coredll.dll")> _ Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer End Function #End Region




Reply With Quote