标签:
最近做一个指纹采集和比对的功能,因为公司整个项目是WEB类型的,所以指纹采集的模块要嵌套在网页中,那只有用ActiveX了,以下是一些操作及效果,做个笔记!
新建用户控件,编写CS代码,如下:
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; }
指纹采集关键代码:
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字符串
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属性
在页面中注册此插件
采集指纹的次数可以自定义,默认为采集三次之后保存,设备是中控的采集器。
标签:
原文地址:http://www.cnblogs.com/allen0118/p/4207008.html