转自: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.

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 frmMainDim Sig_InkCollector As InkCollector 'The InkCollector
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) _Handles Me.LoadSig_InkCollector = New InkCollector(GroupBox1.Handle)Sig_InkCollector.Enabled = TrueSig_InkCollector.AutoRedraw = TrueEnd 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相关推荐

  1. LeetCode刷题记录15——21. Merge Two Sorted Lists(easy)

    LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) 目录 LeetCode刷题记录15--21. Merge Two Sorted Lists(easy) ...

  2. LeetCode刷题记录14——257. Binary Tree Paths(easy)

    LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...

  3. LeetCode刷题记录13——705. Design HashSet(easy)

    LeetCode刷题记录13--705. Design HashSet(easy) 目录 LeetCode刷题记录13--705. Design HashSet(easy) 前言 题目 语言 思路 源 ...

  4. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  5. LeetCode刷题记录11——290. Word Pattern(easy)

    LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...

  6. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

  7. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

  8. LeetCode刷题记录8——605. Can Place Flowers(easy)

    LeetCode刷题记录8--605. Can Place Flowers(easy) 目录 LeetCode刷题记录8--605. Can Place Flowers(easy) 题目 语言 思路 ...

  9. LeetCode刷题记录7——824. Goat Latin(easy)

    LeetCode刷题记录7--824. Goat Latin(easy) 目录 LeetCode刷题记录7--824. Goat Latin(easy) 题目 语言 思路 后记 题目 题目需要将一个输 ...

最新文章

  1. WheelView实现省市区三级联动(数据库实现版本号附带完整SQL及数据)
  2. linux nslookup脚本,Linux中nslookup命令起什么作用呢?
  3. h5页面禁止复制_H5移动端页面禁止复制技巧
  4. 为什么耗资数亿的12306一直都非常难用?
  5. 查询存储过程,数据库对象的创建历史
  6. MySQL 双主单写,主库偶尔出现大量延迟的原因
  7. 吴恩达神经网络和深度学习-学习笔记-21-何时该改变开发集+测试集或指标
  8. 数据库原理与应用 基于SQL Server 2005pdf
  9. 打磨TF卡叠加SIM的注意问题
  10. 好程序员web前端培训分享JavaScript学习笔记ajax及ajax封装
  11. 超酷计算机病毒,世界上十种最强的计算机病毒,最著名的计算机病毒都在这里!...
  12. 吉林大学学生邮箱接收服务器地址
  13. 电脑关机同步服务器信息失败,电脑同步,更新时间失败,怎么处理?
  14. Application Repository一键启用微信告警通知
  15. 豌豆荚Hack Day:百宝袋负责人访谈
  16. Snowflake Snow Snowflakes(Hash + 链式前向星)
  17. python 如何爬虫wind api数据_Python网络爬虫实战之十:利用API进行数据采集
  18. 如何看自己系统是否支持DirectX 9.0c
  19. 用webbroswer控件自动点击确定按钮
  20. MyBatis中小于号“<“的使用

热门文章

  1. Shopee虾皮网|打造Shopee爆款前,必须分析七大数据!
  2. 什么是m叉树_树、二叉树、二叉搜索树的实现和特性
  3. case when then else end的用法
  4. VT-x is disabled in BIOS问题的解决步骤
  5. 57套古风字体462套英文字体79套中文字体
  6. 以前的面试题对不上现在的新技术,整理出一套2020最新版面试题供大家参考
  7. c语言中y=0x20什么意思,ASCII码0x20之前的码分别是什么意义?
  8. 织梦的网站地图怎么做html,织梦(dedecms)网站地图改变生成目录的方法
  9. Mysql建库建表语句分享
  10. 物联网产业爆发前夜,2020投资正当时