コード例 #1
0
        /// <summary>
        /// 生成指纹图像
        /// </summary>
        /// <returns></returns>
        public bool GetFingerImage(UInt32 nDevAddr, int iBuffer)
        {
            byte[] ImgData = new byte[Image_Size];
            int[]  ImgLen  = new int[1];
            int    timeout = 0;

            //while (Ret == 2)
            //{
            //    Ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象
            //    this.MessageStr = "请将手指平放在传感器上...";
            //    Thread.Sleep(100);
            //    timeout++;
            //    if (timeout > 100)
            //        return false;
            //}

            Ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象
            if (Ret == 2)
            {
                this.MessageStr = "请将手指平放在传感器上...";
            }
            else if (Ret == 0)
            {
                this.MessageStr = "获取图像成功...";
                if (IsUsb)
                {
                    this.MessageStr = "正在上传图像请等待...";
                    Ret             = Fingerdll.ZAZUpImage(hHandle, nDevAddr, ImgData, ImgLen); //上传图象
                    if (Ret != 0)
                    {
                        this.MessageStr = Fingerdll.ZAZErr2Strt(Ret);
                        return(false);
                    }
                    string strFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZAZFinger.bmp");
                    Ret = Fingerdll.ZAZImgData2BMP(ImgData, strFile);
                    if (Ret != 0)
                    {
                        this.MessageStr = Fingerdll.ZAZErr2Strt(Ret);
                        return(false);
                    }
                    FileStream pFileStream = new FileStream(strFile, FileMode.Open, FileAccess.Read);
                    this.CurrentImage = Image.FromStream(pFileStream);
                    return(true);
                }

                //////////////////////////////////////////////////////////////////////////
                /****************生成特征 *********/
                Ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer);  //生成模板
                if (Ret != 0)
                {
                    this.MessageStr = Fingerdll.ZAZErr2Strt(Ret);
                    return(false);
                }
                else
                {
                    this.MessageStr = "生成指纹特征" + iBuffer.ToString();
                }
BEIG2:
                if (ret == 0)
                {                                                               //超时判断
                    Ret             = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象
                    this.MessageStr = "等待手指拿开-";
                    goto BEIG2;
                }
                if (Ret == 1)
                {
                    this.MessageStr = Fingerdll.ZAZErr2Strt(Ret);
                    return(false);
                }
            }
            else
            {
                this.MessageStr = Fingerdll.ZAZErr2Strt(ret);
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// 获取指纹
        /// </summary>
        /// <param name="buffer">指纹在设备中临时存放位置 1 2</param>
        /// <returns></returns>
        public bool GetFinger(int buffer = 1)
        {
            TimeOut = 20;
            int ret = 0;

            byte[] ImgData = new byte[Image_Size];
            int[]  ImgLen  = new int[1];
            int    iBuffer = buffer;

BEIG1:
            ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr);  //获取图象
            if (ret == 0)
            {
                ShowInfomation("获取图像成功...");
            }
            else if (ret == 2)
            {
                //超时判断
                ShowInfomation("等待手指平放在传感器上-" + TimeOut.ToString() + "秒");
                if (TimeOut < 0)
                {
                    ShowInfomation("等待超时");
                    return(false);
                }
                TimeOut--;
                Thread.Sleep(1000);
                goto BEIG1;
            }
            else
            {
                ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return(false);
            }

            //////////////////////////////////////////////////////////////////////////
            //不涉及图像,下面可以省略
            /****************上传图像*********/

            ShowInfomation("正在上传图像请等待...");
            ret = Fingerdll.ZAZUpImage(hHandle, nDevAddr, ImgData, ImgLen);  //上传图象
            if (ret != 0)
            {
                ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return(false);
            }
            //strFile = System.Windows.Forms.Application.StartupPath + "\\ZAZFinger.bmp";
            string strFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZAZFinger.bmp");

            ret = Fingerdll.ZAZImgData2BMP(ImgData, strFile);
            if (ret != 0)
            {
                ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return(false);
            }
            ShowImage(strFile);
            //ret = Fingerdll.ZAZShowFingerData(fpbmp.Handle, ref ImgData[0]);
            //////////////////////////////////////////////////////////////////////////
            /****************生成特征 *********/
            ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer);  //生成模板
            if (ret != 0)
            {
                ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return(false);
            }
            else
            {
                ShowInfomation("生成指纹特征" + buffer.ToString());
            }
            Thread.Sleep(10);
BEIG2:
            if (ret == 0)
            {                                                   //超时判断
                string strTemp;
                ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象
                ShowInfomation("等待手指拿开-");
                // if (timeout < 0)
                // { ShowInfomation("等待超时"); return 0; }
                // timeout--;
                // Thread.Sleep(10);
                goto BEIG2;
            }
            else if (ret == 1)
            {
                ShowInfomation(Fingerdll.ZAZErr2Strt(ret));
                return(false);
            }
            return(true);
        }