程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#開發ActiveX控件及指紋采集

C#開發ActiveX控件及指紋采集

編輯:C#入門知識

C#開發ActiveX控件及指紋采集


最近做一個指紋采集和比對的功能,因為公司整個項目是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屬性

圖片

在頁面中注冊此插件

圖片

圖片

圖片

圖片

圖片

圖片

圖片

圖片

圖片

采集指紋的次數可以自定義,默認為采集三次之後保存,設備是中控的采集器。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved