csharp: winform using Microsoft.Ink(Tablet PC API) create Signature image

  1 /*
  2 下載:
  3 //Microsoft Windows XP Tablet PC Edition 2005 Recognizer Pack http://www.microsoft.com/zh-cn/download/details.aspx?id=1601
  4 //Microsoft Windows XP Tablet PC Edition Software Development Kit 1.7  http://www.microsoft.com/en-us/download/details.aspx?id=20039
  5  * Microsoft Speech Platform - Software Development Kit (SDK) (Version 11) http://www.microsoft.com/en-us/download/details.aspx?id=27226
  6  * Microsoft SDKs http://msdn.microsoft.com/en-us/dd299405.aspx
  7  *Microsoft.Ink 命名空间  http://msdn.microsoft.com/zh-cn/library/microsoft.ink%28v=vs.90%29.aspx
  8  * 
  9  *  安裝的文件在://Program Files\Microsoft Tablet PC Platform SDK\Include\Microsoft.Ink.dll
 10  *  在Windows XP sp3 環境下測試
 11  */
 12 
 13 using System;
 14 using System.Collections.Generic;
 15 using System.ComponentModel;
 16 using System.Data;
 17 using System.Drawing;
 18 using System.Linq;
 19 using System.Text;
 20 using System.Windows.Forms;
 21 using System.IO;
 22 using Microsoft.Ink; //引用:Micosoft Tablet PC
 23 
 24 
 25 
 26 
 27 
 28 namespace ChineseCalenderGeovinDu
 29 {
 30     /// <summary>
 31     /// 20120914
 32     /// 塗聚文
 33     /// 捷為工作室
 34     /// 締友計算機信息技術有限公司
 35     /// </summary>
 36     public partial class TabletPCForm : Form
 37     {
 38 
 39         InkOverlay inkOverlay;
 40         InkPicture InkPicture1 = new InkPicture();
 41 
 42         /// <summary>
 43         /// 
 44         /// </summary>
 45         public TabletPCForm()
 46         {
 47             InitializeComponent();
 48         }
 49         /// <summary>
 50         /// 
 51         /// </summary>
 52         /// <param name="sender"></param>
 53         /// <param name="e"></param>
 54         private void TabletPCForm_Load(object sender, EventArgs e)
 55         {
 56             inkOverlay = new InkOverlay();
 57             inkOverlay.Handle = this.pictureBox1.Handle;// this.Handle;//整個窗體
 58             inkOverlay.Enabled = true;
 59 
 60         }
 61        
 62         /// <summary>
 63         /// 保存圖片
 64         /// </summary>
 65         /// <param name="sender"></param>
 66         /// <param name="e"></param>
 67         private void buttonSave_Click(object sender, EventArgs e)
 68         {
 69             SaveFileDialog sfd = new SaveFileDialog();
 70             sfd.Filter = "GIF IMAGES(*.gif)|*.gif";
 71             if (sfd.ShowDialog() == DialogResult.OK)
 72             {
 73                 txtpath.Text = sfd.FileName;
 74                 FileStream gifFile;
 75                 byte[] fortifiedGif = null;
 76                 // open the file for writing
 77                 gifFile = File.OpenWrite(txtpath.Text);
 78                 // Generate the fortified GIF represenation of the ink
 79                 fortifiedGif = inkOverlay.Ink.Save(PersistenceFormat.Gif);
 80                 // Write and close the gif file
 81                 gifFile.Write(fortifiedGif, 0, fortifiedGif.Length);
 82                 gifFile.Close();
 83                 this.pictureBox2.Image = Image.FromFile(sfd.FileName);
 84             }
 85         }
 86 
 87        
 88         /// <summary>
 89         /// 清除
 90         /// </summary>
 91         /// <param name="sender"></param>
 92         /// <param name="e"></param>
 93         private void buttonClear_Click(object sender, EventArgs e)
 94         {
 95             inkOverlay.Enabled = false;
 96             inkOverlay.Ink.DeleteStrokes();
 97             this.pictureBox1.Invalidate() ;
 98             this.pictureBox2.Invalidate();
 99             inkOverlay.Enabled = true;
100         }
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111     }
112 
113 }

 

 

posted @ 2012-09-14 17:04  ®Geovin Du Dream Park™  阅读(1064)  评论(0编辑  收藏  举报