Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pocket pc compact .net framework signature image class 1

Status
Not open for further replies.

jasc2k

Programmer
Nov 2, 2005
113
GB
hi all,

I am working on a signature capture control class provided by microsoft :~ from
using the vb.net compact frameworks

I have adapted the backend to have an SQL connection to store a load of signatures at a time.
I have one column inside the database named 'recSign' defined as an 'image' attribute

From the signature class I am using _signature.signatureBits byte array and storing it to the database image column.
My problem is I believe the byte array is not a true image representation as I am having issues reinterperting it as an image.

For instance when the database is viewed within the visual basic view the image is a red cross.
What I would like to be able to do is store the signature capture as a pure image inside the database so that 3rd party programs would read the database column and show a proper image.

I truly hope someone understands this and can provide some help
I will post the signature class next.
(I have tried things like image.fromstream but the compact framwork will not compile this, lol)

Many thanks

- free mp3 downloads and streaming
 
Code:
'	SignatureControl class
'	--
'	Collects and displays a signature. The signature is made up of 
'	a list of line segments. Each segment contains an array of points 
'	(x and y coordinates). 
'
'	Draws to a memory bitmap to prevent flickering.
'
'	Raises the SignatureUpdate event when a new segment is added to 
'	the signature.


' Custom control that collects and displays a signature.
' [URL unfurl="true"]http://msdn2.microsoft.com/en-us/library/aa446559.aspx#ppcsignatureapp_topic6[/URL]

Public Class SignatureControl
	Inherits Control

	' gdi objects
	Private _bmp As Bitmap
	Private _graphics As Graphics
	Private _pen As New Pen(Color.Black)

	' list of line segments
	Private _lines As New ArrayList

	' the current line segment
	Private _points As New ArrayList
	Private _lastPoint As New Point(0, 0)

	' if drawing signature or not
	Private _collectPoints As Boolean = False

	' notify parent that line segment was updated
	Public Event SignatureUpdate As EventHandler

	' List of signature line segments.
	Public ReadOnly Property Lines() As ArrayList
		Get
			Return _lines
		End Get
    End Property

    Public ReadOnly Property Bmp() As Bitmap
        Get
            Return _bmp
        End Get
    End Property

	' Return the signature flattened to a stream of bytes.
	Public ReadOnly Property SignatureBits() As Byte()
		Get
			Return SignatureData.GetBytes(Me.Width, Me.Height, _lines)
		End Get
	End Property

	Public Sub New()
	End Sub

	Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
		' blit the memory bitmap to the screen
		' we draw on the memory bitmap on mousemove so there
		' is nothing else to draw at this time (the memory 
		' bitmap already contains all of the lines)
		CreateGdiObjects()
		e.Graphics.DrawImage(_bmp, 0, 0)
	End Sub

	Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
		' don't pass to base since we paint everything, avoid flashing
	End Sub

	Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
		MyBase.OnMouseDown(e)

		' process if currently drawing signature
		If Not _collectPoints Then
			' start collecting points
			_collectPoints = True

			' use current mouse click as the first point
			_lastPoint.X = e.X
			_lastPoint.Y = e.Y

			' this is the first point in the list
			_points.Clear()
			_points.Add(_lastPoint)
		End If
	End Sub


	Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
		MyBase.OnMouseUp(e)

		' process if drawing signature
		If _collectPoints Then
			' stop collecting points
			_collectPoints = False

			' add current line to list of segments
			Dim points(_points.Count - 1) As Point
			Dim i As Integer
			For i = 0 To _points.Count - 1
				Dim pt As Point = CType(_points(i), Point)
				points(i).X = pt.X
				points(i).Y = pt.Y
			Next i

			_lines.Add(points)

			' start over with a new line
			_points.Clear()

			' notify container a new segment was added
			RaiseSignatureUpdateEvent()
		End If
	End Sub

	Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
		MyBase.OnMouseMove(e)

		' process if drawing signature
		If _collectPoints Then
			' add point to current line segment
			_points.Add(New Point(e.X, e.Y))

			' draw the new segment on the memory bitmap
			_graphics.DrawLine(_pen, _lastPoint.X, _lastPoint.Y, e.X, e.Y)

			' update the current position
			_lastPoint.X = e.X
			_lastPoint.Y = e.Y

			' display the updated bitmap
			Invalidate()
		End If
	End Sub

	' Clear the signature.
	Public Sub Clear()
		_lines.Clear()
		InitMemoryBitmap()
		Invalidate()
	End Sub

	' Create any GDI objects required to draw signature.
	Private Sub CreateGdiObjects()
		' only create if don't have one or the size changed
		If _bmp Is Nothing Then
			InitMemoryBitmap()
		ElseIf _bmp.Width <> Me.Width Or _bmp.Height <> Me.Height Then
			InitMemoryBitmap()
		End If
	End Sub

	' Create a memory bitmap that is used to draw the signature.
	Private Sub InitMemoryBitmap()
		' load the background image
		_bmp = [Global].LoadImage("sign here.png")

		' get graphics object now to make drawing during mousemove faster
		_graphics = Graphics.FromImage(_bmp)
	End Sub

	' Notify container that a line segment has been added.
	Private Sub RaiseSignatureUpdateEvent()
		RaiseEvent SignatureUpdate(Me, EventArgs.Empty)
	End Sub
End Class

again thanks

- free mp3 downloads and streaming
 
You seem to be correct. You are missing the part that say 100% what is happening (SignatureData in SignatureBites isn't declared anywhere in that code sample), but _lines is nothing more than an Array of points. What you are saving is a map of how the signature is drawn not a picture of it. The problem is you are drawing on a control and I'm not sure how to covert that into a picture since I've never done it. I think I have seen it done before. Sadly I don't have the time right now to help figure it out.

The only other suggestion I can make. I helped someone with that before, but couldn't find the original thread. Here as a drawing version of it to look at for a starting point.
thread796-1579282

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Wow I need to slow down a bit. Hehe. That last part should read:

The only other suggestion I can make [red]is to inherit from a picture box instead[/red]. I helped someone with that before, but couldn't find the original thread. Here as a drawing version of it to look at for a starting point.
thread796-1579282: Ghost images on saved image

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
thanks for your confirmation at least I am not going mad. I think I will be working on this issue for a while by the looks of it lol so if you do think of anything please let me know.
I will check out your suggested thread and see if I can make something from it, will keep the thread updated!

Many thanks

- free mp3 downloads and streaming
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top