1. 程式人生 > >InkCollector Signiture Made Easy

InkCollector Signiture Made Easy

轉自:http://www.codeproject.com/Articles/105570/InkCollector-Signiture-Made-Easy

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

相關推薦

InkCollector Signiture Made Easy

轉自:http://www.codeproject.com/Articles/105570/InkCollector-Signiture-Made-Easy The following article is useful when trying to import Ink

Redux Form made easy

The problem:Redux-form is a popular repository to render react forms.As is it better described in the github repository page:A Higher Order Component using

Curiosity-Driven Learning made easy Part I

In the recent years, we’ve seen a lot of innovations in Deep Reinforcement Learning. From DeepMind and the Deep Q learning architecture in 2014 to OpenAI p

Accessibility Made Easy with Angular CDK

Keyboard focus and navigation are essential when developing for the accessible web. Many users rely on a keyboard when they surf the web.If a user doesn’t

Authentication Made Easy with Auth0: Part 1

Authentication Made Easy with Auth0: Part 1Through example, we will demonstrate how to use Auth0 to secure a Node.js (Express) API that is accessed by a si

Web Monitorng Made Easy

Obserwise tracks any web page you want by taking screenshots and comparing them periodically. You can check it at https://obserwise.datapare.com/

ES6 development environment made easy with babel, gulp and webpack!

ES6 development environment made easy with babel, gulp and webpack!Hello, everyone!Yes, I know, this is yet another tutorial, aiming to incorporate the buz

scripting containers made easy

Introducing conu – Scripting Containers Made Easier

AWS Lambda Functions Made Easy

AWS Lambda Functions Made EasyA Step by Step Guide with Code Snippets for Packing Your Python 2.7 Function for AWS LambdaBackgroundI hope the code in this

Fleet Management Made Easy with Auto Scaling

If your application runs on Amazon EC2 instances, then you have what’s referred to as a ‘fleet’. This is true even if your fleet is just a single

Pipelines For Container Applications Made Easy with mu

Amazon Elastic Container Service (ECS) is a great way to deploy containerized microservices. mu is an open source tool from Stelligent th

Simple Data Pipe: cloud data movement made easy

Cloud data movement made easy. Here’s the challenge of data warehousing in the “API economy”: developers and their services work more

學會定製MapReduce裡的partition,sort和grouping,Secondary Sort Made Easy

通過初期的幾個開發員培訓班,我發現有不少學員容易“偏愛”預設的MapReduce行為,而忽略如何在程式碼里根據自己應用的需要來定製不同於系統預設的行為。這篇文章結合Secondary Sort來介紹“Shuffle & Sort”裡涉及到的三個重要操作。 預設情況下

《TestComplete Made Easy》讀書筆記

《 TestComplete Made Easy 》下載: 《 TestComplete Made Easy 》讀書筆記( 1 ) -TestComplete 簡介 TestComplete 是這幾年測試工具領域異軍突起的

Qt音樂播放器制作(二)Easy Player

滾動 支持 是個 blog 音樂 音樂播放器 div iss size 兩天沒有公布新的動態。主要原因還是個人的生活和工作時間限制,如今趕晚貼出第二版。先放個圖: 自上次公布第一個版本號以來,又進行了多次改動,主要變化在於: (1)依照上次的計劃又一次設計了界面

[ACM] POJ 3740 Easy Finding (DFS)

cas oss miss 矩陣 org fin contest std size Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16202 Accepted: 4349

理解Paxos Made Practical

並運行 execute ase 就會 backup 理解 prim 中一 ron Paxos Made Practical 當一個組中一臺機器提出一個值時,其它成員機器通過PAXOS算法在這個值上達成一致。 Paxos分三個階段。 第一階段: 提出者會選出一個

【POJ3740】Easy Finding DLX(Dancing Links)精確覆蓋問題

ren .cn string 應該 進行 int 函數 操作 urn 題意:多組數據。每組數據給你幾行數,要求選出當中幾行,使得每一列都有且僅有一個1,詢問是可不可行,或者說能不能找出來。 題解:1、暴搜。2、DLX(Dancing links)。 本文寫的是DLX。算

Easy sssp(spfa)

long long empty define lan true 超時 cnblogs space har vijos 1053 Easy sssp 方法:用spfa判斷是否存在負環 描述 輸入數據給出一個有N(2 <= N <= 1,000)個

Leetcode--easy系列10

height per ive bsp weight itself val rtt sizeof #205 Isomorphic Strings Given two strings s and t, determine if they are isomorphic.