C#开发ActiveX控件及指纹采集_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#开发ActiveX控件及指纹采集

C#开发ActiveX控件及指纹采集

 2015/1/9 14:54:29  GC2013  程序员俱乐部  我要评论(0)
  • 摘要:最近做一个指纹采集和比对的功能,因为公司整个项目是WEB类型的,所以指纹采集的模块要嵌套在网页中,那只有用ActiveX了,以下是一些操作及效果,做个笔记!新建用户控件,编写CS代码,如下:
  • 标签:C# 开发 控件

class="FocusMe">最近做一个指纹采集和比对的功能,因为公司整个项目是WEB类型的,所以指纹采集的模块要嵌套在网页中,那只有用ActiveX了,以下是一些操作及效果,做个笔记!

新建用户控件,编写CS代码,如下:

 

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 monospace !important; font-size: 1em !important; font-style: normal !important; font-weight: normal !important; vertical-align: baseline !important; float: none !important; position: static !important; min-height: inherit !important; box-sizing: content-box !important;">using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; using System.IO; using System.Reflection;     namespace FingerTool {     [Guid("5136CBA1-59B0-4A96-B2DC-64062A81F377")]     public partial class FingerToolUC : UserControl,IObjectSafety     {         public FingerToolUC()         {             InitializeComponent();         }         FrmMain fm = null;         public void ShowSettingForm()         {             if (fm == null)             {                 fm = new FrmMain();             }                           fm.ShowDialog();         }             #region 调用JS接口           [ComImport, Guid("00000118-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]         public interface IOleClientSite         {             void SaveObject();               void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);               void GetContainer(out IOleContainer ppContainer);               void ShowObject();               void OnShowWindow(bool fShow);               void RequestNewObjectLayout();           }           [ComImport, Guid("0000011B-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]         public interface IOleContainer         {               void EnumObjects([In, MarshalAs(UnmanagedType.U4)] int grfFlags,                [Out, MarshalAs(UnmanagedType.LPArray)] object[] ppenum);               void ParseDisplayName([In, MarshalAs(UnmanagedType.Interface)] object pbc,                [In, MarshalAs(UnmanagedType.BStr)] string pszDisplayName,                [Out, MarshalAs(UnmanagedType.LPArray)] int[] pchEaten,                [Out, MarshalAs(UnmanagedType.LPArray)] object[] ppmkOut);               void LockContainer([In, MarshalAs(UnmanagedType.I4)] int fLock);           }           #endregion           #region IE 安全接口         private const string _IID_IDispatch = "{00020400-0000-0000-C000-000000000046}";         private const string _IID_IDispatchEx = "{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";         private const string _IID_IPersistStorage = "{0000010A-0000-0000-C000-000000000046}";         private const string _IID_IPersistStream = "{00000109-0000-0000-C000-000000000046}";         private const string _IID_IPersistPropertyBag = "{37D84F60-42CB-11CE-8135-00AA004BB851}";           private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;         private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;         private const int S_OK = 0;         private const int E_FAIL = unchecked((int)0x80004005);         private const int E_NOINTERFACE = unchecked((int)0x80004002);           private bool _fSafeForScripting = true;         private bool _fSafeForInitializing = true;         public int GetInterfaceSafetyOptions(ref Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions)         {             int Rslt = E_FAIL;             string strGUID = riid.ToString("B");             pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;             switch (strGUID)             {                 case _IID_IDispatch:                 case _IID_IDispatchEx:                     Rslt = S_OK;                     pdwEnabledOptions = 0;                     if (_fSafeForScripting == true)                         pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;                     break;                 case _IID_IPersistStorage:                 case _IID_IPersistStream:                 case _IID_IPersistPropertyBag:                     Rslt = S_OK;                     pdwEnabledOptions = 0;                     if (_fSafeForInitializing == true)                         pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;                     break;                 default:                     Rslt = E_NOINTERFACE;                     break;             }               return Rslt;         }

 

指纹采集关键代码:

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 private void axZKFPEngX1_OnImageReceived(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnImageReceivedEvent e)         {             if (!e.aImageValid) return;             if (axZKFPEngX1.IsDisposed) return;             try             {                 if (pictureBox1.Image != null)                 {                     pictureBox1.Image.Dispose();//释放文件资源                     pictureBox1.Image = null;//清除图片                 }                 if (!System.IO.Directory.Exists(mvPath))                 {                     System.IO.Directory.CreateDirectory(mvPath);                 }                   string FilePath = mvPath + "\\" + Guid.NewGuid().ToString() + ".bmp";                   axZKFPEngX1.SaveBitmap(FilePath);//保存新文件                 pictureBox1.Image = System.Drawing.Bitmap.FromFile(FilePath);//显示图片                 pictureBox1.Refresh();                   if (this.txtValue.Text.Trim() != "")                 {                     SetMsg("", "Control");                 }             }             catch (Exception ex)             {                 MessageBox.Show(ex.Message);             }         }      private void axZKFPEngX1_OnFeatureInfo(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnFeatureInfoEvent e)         {             string sTemp = "";             if (axZKFPEngX1.IsRegister)             {                 sTemp = "登记状态:还需要按压:" + (axZKFPEngX1.EnrollIndex - 1).ToString() + "次指纹 ";             }               sTemp = sTemp + "指纹质量";               if (e.aQuality != 0)             {                 if (e.aQuality == 1)                 {                     sTemp = sTemp + "特征点不够";                 }                 else                 {                     sTemp = sTemp + "其它原因导致不能取到指纹特征";                 }             }             else             {                 sTemp = sTemp + "合格";               }             this.lblMessage.Text = sTemp;         }

指纹校验部分,最后保存起来的指纹是转换之后的BASE64字符串

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 string Value_Old="";//已经登记的指纹 string Value_Curr="";//当前的指纹    bool IsOK = false;             bool bRegChange = false;               if (axZKFPEngX1.VerFingerFromStr(ref Value_Old, Value_Curr, false, ref bRegChange))             {                 IsOK = true;             }             if (axZKFPEngX1.VerFingerFromStr(ref Value_Old2, Value_Curr, false, ref bRegChange))             {                 IsOK = true;             }               if (IsOK)             {                 MessageBox.Show("OK");             }             else             {                 MessageBox.Show("NG");               }

设置项目的COM属性

图片

在页面中注册此插件

图片

图片

图片

DBA.jpg" alt="图片" />

图片

图片

图片

图片

图片

采集指纹的次数可以自定义,默认为采集三次之后保存,设备是中控的采集器。

发表评论
用户名: 匿名