//获得验证指纹特征[验证指纹] public string GetFeature() { //指纹特征 // string nRetString = ""; String nRetStringbase64 = ""; int nRets = -1; byte[] pRegs = new byte[512]; //句柄 int objHdl = -1; //返回图像 int nRet = -1; //指纹图像特征 byte[] pReg = new byte[65536]; //图像长度 int pdwLen = pReg.Length; //BP 盒转口控制 char bpControlFlag = 'A'; nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag); BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate); try { objHdl = FingerReaderDllWrapper.TcOpenComm(nCommPort, nBaudRate, 0, 0); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (objHdl == 0) { throw new DeviceException(this.DeviceId, objHdl.ToString(), "打开句柄失败"); } //返回图像信息。 int nRetun = 14; try { nRet = FingerReaderDllWrapper.TcLoadrToPimg(objHdl, nRetun, pReg, ref pdwLen); } catch (Exception e) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (nRet != 0) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹图像失败"); } else { // byte[]转成string // nRetString = System.Text.Encoding.Default.GetString(pReg); // nRetString = Convert.ToBase64String(pReg, 0, pdwLen); //图像处理 /* * FingerReaderDllWrapper.TcSmotImg(pReg,152,200); * FingerReaderDllWrapper.SaveTotalImage("D:\\zlz.bmp",pReg, 152, 200); * // FingerReaderDllWrapper.LoadBinaryFile("D:\\zlz.bmp", pReg, pReg.Length); * Bitmap image = new Bitmap("D:\\zlz.bmp"); * image.Save("D:\\zlz.jpg ", System.Drawing.Imaging.ImageFormat.Jpeg); * image.Dispose(); * int pRegLength= FingerReaderDllWrapper.LoadBinaryFile("D:\\zlz.bmp", pReg, pReg.Length); * nRetStringbase64 = Convert.ToBase64String(pReg, 0, pRegLength); */ nRetStringbase64 = this.getImageUpdate("", pReg, pdwLen); int nIndex = 0; int nRetrn = 1; nRets = FingerReaderDllWrapper.TcMinutFrPimg(objHdl, nIndex, nRetrn, pRegs, ref pdwLen); if (nRets != 0) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹特征失败"); } else { nRetsString = Convert.ToBase64String(pRegs, 0, pdwLen); //蜂鸣器 FingerReaderDllWrapper.TcSubDev(objHdl, 0, 10); } } objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); return(nRetStringbase64); }
/// <summary> /// 获得注册指纹模板 /// </summary> /// <param name="mode">mode:指纹模式,=1,第一次获取指纹模板;=2,第二次获取指纹模板;=3,第三次获取</param> /// <remarks>失败抛异常</remarks> /// <returns>指纹图片信息,Base64存储为字符串,jpg格式;</returns> public string GetTemplate(int nMode) { //指纹图像base64信息 String nRetStringbase64 = ""; //特征合成 nRetsString = ""; string nRetString = ""; StringBuilder readData = new StringBuilder(256); //句柄 int objHdl = -1; //返回图像 int nRet = -1; //指纹图像特征 byte[] pReg = new byte[65536]; //特征合成 int nRets = -1; byte[] pRegs = new byte[512]; //图像长度 int pdwLen = pReg.Length; //第三次注册指纹,特征合成 int pdwLen2 = pRegs.Length; // byte[] CardPUCIIN = new byte[255]; // byte[] pucManaMsg = new byte[255]; //byte[] pucCHMsg = new byte[255]; //byte[] pucPHMsg = new byte[3024]; //BP 盒转口控制 char bpControlFlag = 'A'; nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag); BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate); try { objHdl = FingerReaderDllWrapper.TcOpenComm(nCommPort, nBaudRate, 0, 0); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (objHdl == 0) { throw new DeviceException(this.DeviceId, objHdl.ToString(), "打开句柄失败"); } //返回图像信息。 int nRetun = 14; try { if (0 <= nMode - 1 && nMode - 1 < 3) { nRet = FingerReaderDllWrapper.TcSuperRegist(objHdl, nMode - 1, nRetun, pReg, ref pdwLen); } } catch (Exception e) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (nRet != 0) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹图像信息失败"); } else { // byte[]转成string // nRetString = System.Text.Encoding.Default.GetString(pReg); nRetString = Convert.ToBase64String(pReg, 0, pdwLen); nRetStringbase64 = this.getImageUpdate("", pReg, pdwLen); //蜂鸣器 FingerReaderDllWrapper.TcSubDev(objHdl, 0, 10); } try { if (nMode - 1 == 2) { nRets = FingerReaderDllWrapper.TcSuperRegist(objHdl, nMode, 0, pRegs, ref pdwLen2); if (nRets != 0) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, nRets.ToString(), "特征合成失败"); } else { nRetsString = Convert.ToBase64String(pRegs, 0, pdwLen2); //蜂鸣器 FingerReaderDllWrapper.TcSubDev(objHdl, 0, 20); } } } catch (Exception e) { objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl); return(nRetStringbase64); }