Results 1 to 9 of 9

Thread: Saving a drawn signature as a bitmap

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Saving a drawn signature as a bitmap

    Hello,

    VS 2005 CF 2.0

    I have created a PDA device and will allow the user to write there signature.

    However, I am having problems with the saving part.

    http://msdn2.microsoft.com/en-us/library/aa446559.aspx

    I used the above as a example, and took out all the code I needed to draw the signature and the new button.

    I need to save the signature and add it to the database as an image. I think I need to convert the signature to an bitmap, but not sure how to do this.

    Many thanks for any help and advice,

    Steve
    steve

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Saving a drawn signature as a bitmap

    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:
    1. Code SnippetPrivate Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click
    2.  
    3. Try
    4.  
    5. Dim bmp As New Bitmap(Me.PictureBox1.Image)
    6.  
    7. Using g As Graphics = Graphics.FromImage(bmp)
    8.  
    9. Using pen As Pen = New Pen(Color.Red, 2)
    10.  
    11. For Each pointList As List(Of Point) In strokeCollection
    12.  
    13. If (pointList.Count >= 2) Then
    14.  
    15. g.DrawLines(pen, pointList.ToArray())
    16.  
    17. End If
    18.  
    19. Next pointList
    20.  
    21. End Using
    22.  
    23. End Using
    24.  
    25. Catch ex As Exception
    26.  
    27. MsgBox(ex.Message)
    28.  
    29. End Try
    30.  
    31. 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:
    1. Code Snippet
    2.  
    3. #Region "Local Variables"
    4.  
    5. Private lastPoint As Point
    6.  
    7. Private strokeCollection As New List(Of List(Of Point))
    8.  
    9. Private currentStroke As New List(Of Point)
    10.  
    11. #End Region
    12.  
    13. #Region "Constructor"
    14.  
    15. Public Sub New()
    16.  
    17. InitializeComponent()
    18.  
    19. AddHandler PictureBox1.Paint, AddressOf PictureBox1_Paint
    20.  
    21. End Sub
    22.  
    23. #End Region
    24.  
    25. #Region "PictureBox1_Paint Event"
    26.  
    27. Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As PaintEventArgs)
    28.  
    29. For Each pointList As List(Of Point) In strokeCollection
    30.  
    31. If pointList.Count >= 2 Then
    32.  
    33. Using pen As New Pen(Color.Black, 2)
    34.  
    35. e.Graphics.DrawLines(pen, pointList.ToArray())
    36.  
    37. End Using
    38.  
    39. End If
    40.  
    41. Next
    42.  
    43. End Sub
    44.  
    45. #End Region
    46.  
    47. #Region "Picture box mouse down event"
    48.  
    49. Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    50.  
    51. Try
    52.  
    53. Me.lastPoint = New Point(e.X, e.Y)
    54.  
    55. Me.currentStroke = New List(Of Point)
    56.  
    57. Me.strokeCollection.Add(Me.currentStroke)
    58.  
    59. Catch ex As Exception
    60.  
    61. MsgBox(ex.Message)
    62.  
    63. End Try
    64.  
    65. End Sub
    66.  
    67. #End Region
    68.  
    69. #Region "Picture box mouse move event"
    70.  
    71. Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    72.  
    73. Dim hDC As IntPtr = GetDC(Me.PictureBox1.Handle)
    74.  
    75. Using g As Graphics = Graphics.FromHdc(hDC)
    76.  
    77. Using pen As Pen = New Pen(Color.Black, 2)
    78.  
    79. g.DrawLine(pen, lastPoint.X, lastPoint.Y, e.X, e.Y)
    80.  
    81. End Using
    82.  
    83. End Using
    84.  
    85. ReleaseDC(Me.PictureBox1.Handle, hDC)
    86.  
    87. Me.lastPoint = New Point(e.X, e.Y)
    88.  
    89. Me.currentStroke.Add(Me.lastPoint)
    90.  
    91. End Sub
    92.  
    93. #End Region
    94.  
    95. #Region "Attributes"
    96.  
    97. <System.Runtime.InteropServices.DllImport("coredll.dll")> _
    98.  
    99. Private Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
    100.  
    101. End Function
    102.  
    103. <System.Runtime.InteropServices.DllImport("coredll.dll")> _
    104.  
    105. Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
    106.  
    107. End Function
    108.  
    109. #End Region
    Last edited by steve_rm; Sep 18th, 2007 at 12:16 PM.
    steve

  3. #3
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Saving a drawn signature as a bitmap

    Hi,
    this sample (http://www.codeproject.com/netcf/Sig...apture_PPC.asp) does what you need, but in c# - you could always use a translator

    There are some questions/notes on the sample you used here
    Last edited by petevick; Sep 18th, 2007 at 03:07 PM.
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Saving a drawn signature as a bitmap

    Hello Petevick,

    Thanks for your reply. However, I would like to get the one that I have already done finished. As I still have a problem with it. I don't really want to start something new, as there is more to learn of what I am doing wrong with my current problem.

    Anyway I have got further now. I have inserted a picture into the image property of the pictureBox1. So don't get the error message like i did in post #2.

    The Error message I am getting now is on the bmp.Save(signaturePath, ImageFormat.Png) "NotSupportedException"

    My code as below:
    vb Code:
    1. Private Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click
    2.         Try
    3.             Dim bmp As New Bitmap(Me.PictureBox1.Image)
    4.  
    5.             Dim signaturePath As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
    6.             signaturePath = IO.Path.Combine(signaturePath, "signature.png")
    7.  
    8.             Using g As Graphics = Graphics.FromImage(bmp)
    9.                 Using pen As Pen = New Pen(Color.Red, 2)
    10.                     For Each pointList As List(Of Point) In strokeCollection
    11.                         If (pointList.Count >= 2) Then
    12.                             g.DrawLines(pen, pointList.ToArray())
    13.                         End If
    14.                     Next pointList
    15.                 End Using
    16.             End Using
    17.             bmp.Save(signaturePath, ImageFormat.Png)
    18.  
    19.         Catch ex As Exception
    20.             MsgBox(ex.Message)
    21.         End Try
    22.     End Sub

    Many Many thanks if you could help me more with this problem.

    Steve
    steve

  5. #5
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Saving a drawn signature as a bitmap

    Hi,
    did you check whether the questions/notes helped with your issue?
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Saving a drawn signature as a bitmap

    hello,

    Thanks for the reply. Yes I did look through the website and downloaded the sample project. But that project is very complicated for me to understand.

    I was using the following from the question/notes but of no help.
    vb Code:
    1. bmp.Save(signaturePath, ImageFormat.Png)
    2.             Me.PictureBox1.Image.Save(signaturePath, ImageFormat.Png)

    Help would be most grateful if you could further explain,

    Many thanks,
    steve

  7. #7
    Banned
    Join Date
    Sep 2007
    Posts
    3

    Re: Saving a drawn signature as a bitmap

    yeah, what's the further explain

  8. #8
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Saving a drawn signature as a bitmap

    Hi,
    what platform are you running on - PPC 2003, WM5 or WM6?

    Try changing if to saving as a .bmp using imageformat.bmp

    You would get an unsupported exception if you tried to save as a .png in PPC2003

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Saving a drawn signature as a bitmap

    Hi Petevick,

    Thank for the reply. Yes I am using Windows Mobile 5.

    I will check this later.

    Thanks,

    Steve
    steve

Posting Permissions

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



Click Here to Expand Forum to Full Width