Click here to Skip to main content
Click here to Skip to main content

InkCollector Signiture Made Easy

, 23 Sep 2010
Rate this:
Please Sign up or sign in to vote.
InkCollector Signiture as a String Made Easy

Introduction

The following article is useful when trying to import Ink into a database. I have tried to keep it as simple as possible.

Example.png

I've successfully used this in my Access database that holds about 500 signatures; the average signature size is about 1500 characters. The largest one on record is 2853 and the smallest one on record is 1139. To store this in a Microsoft Access Database, you will need to save it in a memo field as the maximum number of characters in a Text field is 255.

Using the Code

First add the reference for Microsoft.Ink to your VB Project, next create a group box on your form. Before your form class, add Imports Microsoft.Ink so that a InkCollector control can be created. First, define the InkCollector control. Then, create the control from your form load sub and give it the handle of your group box.

Your code should then look something like this:

Imports Microsoft.Ink 'Required for InkCollector

Public Class frmMain

    Dim Sig_InkCollector As InkCollector 'The InkCollector

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
	Handles Me.Load
        Sig_InkCollector = New InkCollector(GroupBox1.Handle)
        Sig_InkCollector.Enabled = True
        Sig_InkCollector.AutoRedraw = True
    End Sub
End Class

I have just completed adding a function that converts the base64 string to an image so that it can be attached to a RTF, HTML or printed easily.

To Clear the Signiture

Specify call the clear sub from the Signiture module, then specify the InkCollector and the GroupBox which contains the InkCollector control.

Signiture.Clear(Sig_InkCollector, GroupBox1)

To Set the Signiture

To load a signiture Base64 string into the inkCollector, call the following Sub, specify the InkCollector and the GroupBox which contains the InkCollector control, then the Base64 String.

Signiture.SetBase64(Sig_InkCollector, GroupBox1, TextBox1.Text)

To Get the Signiture

To read the Signiture from the InkCollector, call the following function and specify the InkCollector. The Base64 String will be returned.

Textbox1.Text = Signiture.GetBase64(Sig_InkCollector) 

To Convert Base64 to Image

To convert a stored Base64InkSerializedFormat String to an Image, so that the signiture can be displayed in a report.

PictureBox1.Image = Signiture.Base64toImage(TextBox1.Text) 

Source

Imports Microsoft.Ink 'Required for InkPicture
Imports System.Text 'Required by UTF8Encoding
Imports System.IO 'Required by MemoryStream
''' <summary>
''' Signiture Made Easy Module
''' Created by Marco van der Merwe (22 September 2010)
''' </summary>
Module Signiture
''' <summary>
''' Returns String in Format(PersistenceFormat = Base64InkSerializedFormat)
''' </summary>
''' <param name="InkCollector"></param>
''' <returns> String Format(PersistenceFormat = Base64InkSerializedFormat)</returns>
''' <remarks></remarks>
Function GetBase64(ByVal InkCollector As InkCollector) As String
Dim utf8 As UTF8Encoding = New UTF8Encoding()
InkCollector.Enabled = False
Return utf8.GetString(InkCollector.Ink.Save_
	(PersistenceFormat.Base64InkSerializedFormat, CompressionMode.Maximum))
InkCollector.Enabled = True
End Function
''' <summary>
''' Sets the Base 64 Ink from String
''' </summary>
''' <param name="InkCollector"></param>
''' <param name="GroupBox"></param>
''' <param name="Base64"></param>
''' <remarks></remarks>
Sub SetBase64(ByVal InkCollector As InkCollector, _
	ByVal GroupBox As GroupBox, ByVal Base64 As String)
Dim loadedInk As Ink = New Ink()
Dim utf8 As UTF8Encoding = New UTF8Encoding()
InkCollector.Enabled = False
InkCollector.Ink.DeleteStrokes() ' Clear all strokes
loadedInk.Load(utf8.GetBytes(Base64))
InkCollector.Ink = loadedInk
InkCollector.Enabled = True
GroupBox.Invalidate()
End Sub
''' <summary>
''' Clear Signiture
''' </summary>
''' <param name="InkCollector"></param>
''' <param name="GroupBox"></param>
''' <remarks></remarks>
Sub Clear(ByVal InkCollector As InkCollector, ByVal GroupBox As GroupBox)
InkCollector.Enabled = False ' Disable InkPicture to clear
InkCollector.Ink.DeleteStrokes() ' Clear all strokes
GroupBox.Invalidate() ' Redraw frame
InkCollector.Enabled = True ' Reenale InkPicture for entry
End Sub
 
''' <summary>
''' Converts String Format(PersistenceFormat = Base64InkSerializedFormat) 
''' to System.Drawing.Image
''' </summary>
''' <param name="Base64"></param>
''' <returns>System.Drawing.Image</returns>
''' <remarks></remarks>
Function Base64toImage(ByVal Base64 As String) As System.Drawing.Image
Dim utf8 As UTF8Encoding = New UTF8Encoding()
Dim imgSig As System.Drawing.Image
Dim tmploadedInk As Ink = New Ink()
Dim strGIF As String
Dim imageBytes() As Byte
Dim MS As MemoryStream
'Load the Base64 String in Format(PersistenceFormat = Base64InkSerializedFormat) as ink
tmploadedInk.Load(utf8.GetBytes(Base64))
'Convert the ink to Base64 String in format 
'(PersistenceFormat.Gif, CompressionMode.Maximum)
strGIF = Convert.ToBase64String(tmploadedInk.Save_
	(PersistenceFormat.Gif, CompressionMode.Maximum))
'Convert Base64 String to Byte Array
imageBytes = Convert.FromBase64String(strGIF)
MS = New MemoryStream(imageBytes, 0, imageBytes.Length)
' Convert byte[] to Image
MS.Write(imageBytes, 0, imageBytes.Length)
imgSig = Image.FromStream(MS, True)
Return imgSig
End Function
End Module

Points of Interest

I’ve tried everything with InkPicture for about 3 weeks and had no results, until I started using InkCollector. I had many unexplained errors and very little help with InkPicture, this is far easier to use.

I know the Access Database gets quite large, but at least these signitures are secured by a password and my data is at least stored in the same database.

History

  • Added Image Support, to convert Base64InkSerializedFormat string to Image

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

bigbro_1985
Engineer
Qatar Qatar
My love for imagining, designing and creating just about anything REAL or VIRTUAL has lead me on this path. Whether it be 1’s and 0’s, soldering an IC to a PCB or getting under the car just to get my hands dirty, I like to do it DIY.
Life is a journey, and it’s all about learning and creating…
 
Some Achievements in my life:
• Founder of the Doha College Robotics Club
• President and founder of the CNA-Q Robotics Club
• Developed Fly-By-Wire Over Ethernet (FBWOE) for boats.
• Telecommunication Engineering Technology Diploma
• X10 Home Automation system as part of a Green Home project
Developed a Vehicle Accessory Computer Interface (VACI)
• Autonomos Turtle Monitoring Robot
Virtual Autonomous Remote Presence (VARP)
• Electrical Engineering Degree from Purdue
• Various Industrial Automation projects ranging from manufacturing car parts to plastics, shaving cream and even ice-cream. I have worked with various robotic systems, VFD's, HMI's, PLCs, industrial networking/data collection systems, and Machine Vision systems.

Comments and Discussions

 
QuestionC# Pinmembervishal jodh14-May-13 0:40 
Questiongetting signature from databse PinmemberShine10003-Mar-12 5:52 
QuestionLimiting size of signature PinmemberMember 863721411-Feb-12 21:28 
AnswerRe: Limiting size of signature Pinmemberbigbro_198512-Feb-12 4:05 
GeneralMy vote of 4 Pinmembertheanil30-Jan-12 8:27 
good work
QuestionWhere is Microsoft.Ink? Pinmemberadrian lewis15-Sep-11 1:51 
AnswerRe: Where is Microsoft.Ink? Pinmemberbigbro_198515-Sep-11 2:29 
GeneralMy vote of 5 PinmemberMystcreater6-Jul-11 8:21 
QuestionSignature PinmemberLouLanada28-Jun-11 6:43 
AnswerRe: Signature Pinmemberbigbro_198529-Jun-11 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 23 Sep 2010
Article Copyright 2010 by bigbro_1985
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid