|
-
Aug 28th, 2007, 12:59 PM
#1
Thread Starter
Frenzied Member
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
-
Sep 18th, 2007, 12:09 PM
#2
Thread Starter
Frenzied Member
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:
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
Last edited by steve_rm; Sep 18th, 2007 at 12:16 PM.
steve
-
Sep 18th, 2007, 03:00 PM
#3
Frenzied Member
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.
-
Sep 22nd, 2007, 07:04 AM
#4
Thread Starter
Frenzied Member
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:
Private 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)
Dim signaturePath As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
signaturePath = IO.Path.Combine(signaturePath, "signature.png")
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
bmp.Save(signaturePath, ImageFormat.Png)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Many Many thanks if you could help me more with this problem.
Steve
-
Sep 22nd, 2007, 10:20 AM
#5
Frenzied Member
Re: Saving a drawn signature as a bitmap
Hi,
did you check whether the questions/notes helped with your issue?
-
Sep 22nd, 2007, 12:20 PM
#6
Thread Starter
Frenzied Member
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:
bmp.Save(signaturePath, ImageFormat.Png)
Me.PictureBox1.Image.Save(signaturePath, ImageFormat.Png)
Help would be most grateful if you could further explain,
Many thanks,
-
Sep 25th, 2007, 03:36 AM
#7
Banned
Re: Saving a drawn signature as a bitmap
yeah, what's the further explain
-
Sep 26th, 2007, 04:36 AM
#8
Frenzied Member
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
-
Sep 26th, 2007, 11:46 AM
#9
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|