基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Lskj.Control.ZKFinger
{
public class BitmapFormat
{
public struct BITMAPFILEHEADER
{
public ushort bfType;
public int bfSize;
public ushort bfReserved1;
public ushort bfReserved2;
public int bfOffBits;
}
public struct MASK
{
public byte redmask;
public byte greenmask;
public byte bluemask;
public byte rgbReserved;
}
public struct BITMAPINFOHEADER
{
public int biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public int biCompression;
public int biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public int biClrUsed;
public int biClrImportant;
}
/*******************************************
* 函数名称:RotatePic
* 函数功能:旋转图片,目的是保存和显示的图片与按的指纹方向不同
* 函数入参:BmpBuf---旋转前的指纹字符串
* 函数出参:ResBuf---旋转后的指纹字符串
* 函数返回:无
*********************************************/
public static void RotatePic(byte[] BmpBuf, int width, int height, ref byte[] ResBuf)
{
int RowLoop = 0;
int ColLoop = 0;
int BmpBuflen = width * height;
try
{
for (RowLoop = 0; RowLoop < BmpBuflen;)
{
for (ColLoop = 0; ColLoop < width; ColLoop++)
{
ResBuf[RowLoop + ColLoop] = BmpBuf[BmpBuflen - RowLoop - width + ColLoop];
}
RowLoop = RowLoop + width;
}
}
catch (Exception ex)
{
//ZKCE.SysException.ZKCELogger logger = new ZKCE.SysException.ZKCELogger(ex);
//logger.Append();
}
}
/*******************************************
* 函数名称:StructToBytes
* 函数功能:将结构体转化成无符号字符串数组
* 函数入参:StructObj---被转化的结构体
* Size---被转化的结构体的大小
* 函数出参:无
* 函数返回:结构体转化后的数组
*********************************************/
public static byte[] StructToBytes(object StructObj, int Size)
{
int StructSize = Marshal.SizeOf(StructObj);
byte[] GetBytes = new byte[StructSize];
try
{
IntPtr StructPtr = Marshal.AllocHGlobal(StructSize);
Marshal.StructureToPtr(StructObj, StructPtr, false);
Marshal.Copy(StructPtr, GetBytes, 0, StructSize);
Marshal.FreeHGlobal(StructPtr);
if (Size == 14)
{
byte[] NewBytes = new byte[Size];
int Count = 0;
int Loop = 0;
for (Loop = 0; Loop < StructSize; Loop++)
{
if (Loop != 2 && Loop != 3)
{
NewBytes[Count] = GetBytes[Loop];
Count++;
}
}
return NewBytes;
}
else
{
return GetBytes;
}
}
catch (Exception ex)
{
//ZKCE.SysException.ZKCELogger logger = new ZKCE.SysException.ZKCELogger(ex);
//logger.Append();
return GetBytes;
}
}
/*******************************************
* 函数名称:GetBitmap
* 函数功能:将传进来的数据保存为图片
* 函数入参:buffer---图片数据
* nWidth---图片的宽度
* nHeight---图片的高度
* 函数出参:无
* 函数返回:无
*********************************************/
public static void GetBitmap(byte[] buffer, int nWidth, int nHeight, ref MemoryStream ms)
{
int ColorIndex = 0;
ushort m_nBitCount = 8;
int m_nColorTableEntries = 256;
byte[] ResBuf = new byte[nWidth * nHeight];
try
{
BITMAPFILEHEADER BmpHeader = new BITMAPFILEHEADER();
BITMAPINFOHEADER BmpInfoHeader = new BITMAPINFOHEADER();
MASK[] ColorMask = new MASK[m_nColorTableEntries];
//图片头信息
BmpInfoHeader.biSize = Marshal.SizeOf(BmpInfoHeader);
BmpInfoHeader.biWidth = nWidth;
BmpInfoHeader.biHeight = nHeight;
BmpInfoHeader.biPlanes = 1;
BmpInfoHeader.biBitCount = m_nBitCount;
BmpInfoHeader.biCompression = 0;
BmpInfoHeader.biSizeImage = 0;
BmpInfoHeader.biXPelsPerMeter = 0;
BmpInfoHeader.biYPelsPerMeter = 0;
BmpInfoHeader.biClrUsed = m_nColorTableEntries;
BmpInfoHeader.biClrImportant = m_nColorTableEntries;
//文件头信息
BmpHeader.bfType = 0x4D42;
BmpHeader.bfOffBits = 14 + Marshal.SizeOf(BmpInfoHeader) + BmpInfoHeader.biClrUsed * 4;
BmpHeader.bfSize = BmpHeader.bfOffBits + ((((BmpInfoHeader.biWidth * BmpInfoHeader.biBitCount + 31) / 32) * 4) * BmpInfoHeader.biHeight);
BmpHeader.bfReserved1 = 0;
BmpHeader.bfReserved2 = 0;
ms.Write(StructToBytes(BmpHeader, 14), 0, 14);
ms.Write(StructToBytes(BmpInfoHeader, Marshal.SizeOf(BmpInfoHeader)), 0, Marshal.SizeOf(BmpInfoHeader));
//调试板信息
for (ColorIndex = 0; ColorIndex < m_nColorTableEntries; ColorIndex++)
{
ColorMask[ColorIndex].redmask = (byte)ColorIndex;
ColorMask[ColorIndex].greenmask = (byte)ColorIndex;
ColorMask[ColorIndex].bluemask = (byte)ColorIndex;
ColorMask[ColorIndex].rgbReserved = 0;
ms.Write(StructToBytes(ColorMask[ColorIndex], Marshal.SizeOf(ColorMask[ColorIndex])), 0, Marshal.SizeOf(ColorMask[ColorIndex]));
}
//图片旋转,解决指纹图片倒立的问题
RotatePic(buffer, nWidth, nHeight, ref ResBuf);
ms.Write(ResBuf, 0, nWidth * nHeight);
}
catch (Exception ex)
{
// ZKCE.SysException.ZKCELogger logger = new ZKCE.SysException.ZKCELogger(ex);
// logger.Append();
}
}
/*******************************************
* 函数名称:WriteBitmap
* 函数功能:将传进来的数据保存为图片
* 函数入参:buffer---图片数据
* nWidth---图片的宽度
* nHeight---图片的高度
* 函数出参:无
* 函数返回:无
*********************************************/
public static void WriteBitmap(byte[] buffer, int nWidth, int nHeight)
{
int ColorIndex = 0;
ushort m_nBitCount = 8;
int m_nColorTableEntries = 256;
byte[] ResBuf = new byte[nWidth * nHeight];
try
{
BITMAPFILEHEADER BmpHeader = new BITMAPFILEHEADER();
BITMAPINFOHEADER BmpInfoHeader = new BITMAPINFOHEADER();
MASK[] ColorMask = new MASK[m_nColorTableEntries];
//图片头信息
BmpInfoHeader.biSize = Marshal.SizeOf(BmpInfoHeader);
BmpInfoHeader.biWidth = nWidth;
BmpInfoHeader.biHeight = nHeight;
BmpInfoHeader.biPlanes = 1;
BmpInfoHeader.biBitCount = m_nBitCount;
BmpInfoHeader.biCompression = 0;
BmpInfoHeader.biSizeImage = 0;
BmpInfoHeader.biXPelsPerMeter = 0;
BmpInfoHeader.biYPelsPerMeter = 0;
BmpInfoHeader.biClrUsed = m_nColorTableEntries;
BmpInfoHeader.biClrImportant = m_nColorTableEntries;
//文件头信息
BmpHeader.bfType = 0x4D42;
BmpHeader.bfOffBits = 14 + Marshal.SizeOf(BmpInfoHeader) + BmpInfoHeader.biClrUsed * 4;
BmpHeader.bfSize = BmpHeader.bfOffBits + ((((BmpInfoHeader.biWidth * BmpInfoHeader.biBitCount + 31) / 32) * 4) * BmpInfoHeader.biHeight);
BmpHeader.bfReserved1 = 0;
BmpHeader.bfReserved2 = 0;
Stream FileStream = File.Open("finger.bmp", FileMode.Create, FileAccess.Write);
BinaryWriter TmpBinaryWriter = new BinaryWriter(FileStream);
TmpBinaryWriter.Write(StructToBytes(BmpHeader, 14));
TmpBinaryWriter.Write(StructToBytes(BmpInfoHeader, Marshal.SizeOf(BmpInfoHeader)));
//调试板信息
for (ColorIndex = 0; ColorIndex < m_nColorTableEntries; ColorIndex++)
{
ColorMask[ColorIndex].redmask = (byte)ColorIndex;
ColorMask[ColorIndex].greenmask = (byte)ColorIndex;
ColorMask[ColorIndex].bluemask = (byte)ColorIndex;
ColorMask[ColorIndex].rgbReserved = 0;
TmpBinaryWriter.Write(StructToBytes(ColorMask[ColorIndex], Marshal.SizeOf(ColorMask[ColorIndex])));
}
//图片旋转,解决指纹图片倒立的问题
RotatePic(buffer, nWidth, nHeight, ref ResBuf);
//写图片
TmpBinaryWriter.Write(ResBuf);
FileStream.Close();
TmpBinaryWriter.Close();
}
catch (Exception ex)
{
//ZKCE.SysException.ZKCELogger logger = new ZKCE.SysException.ZKCELogger(ex);
//logger.Append();
}
}
}
}
@@ -0,0 +1,176 @@
using libzkfpcsharp;
using Lskj.Core;
using Lskj.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Media.Imaging;
namespace Lskj.Control.ZKFinger
{
public class FingerHelper
{
public bool IsInit = false;
public bool IsOpen = false;
public int DeviceCount = 0;
public IntPtr mDevHandle = IntPtr.Zero;
public IntPtr mDBHandle = IntPtr.Zero;
public IntPtr FormHandle = IntPtr.Zero;
public bool bIsTimeToDie = false;
public bool IsRegister = false;
public bool bIdentify = true;
public byte[] FPBuffer;
public int RegisterCount = 0;
public const int REGISTER_FINGER_COUNT = 3;
public byte[][] RegTmps = new byte[3][];
public byte[] RegTmp = new byte[2048];
public byte[] CapTmp = new byte[2048];
public int cbCapTmp = 2048;
public int cbRegTmp = 0;
public int iFid = 1;
public int mfpWidth = 0;
public int mfpHeight = 0;
public FingerHelper()
{
if (!IsInit)
{
InitFinger();
}
if (IsInit && !IsOpen)
{
OpenFinger();
}
}
/// <summary>
/// 初始化识别器
/// </summary>
/// <returns></returns>
public bool InitFinger()
{
try
{
int ret = zkfperrdef.ZKFP_ERR_OK;
if ((ret = zkfp2.Init()) == zkfperrdef.ZKFP_ERR_OK)
{
DeviceCount = zkfp2.GetDeviceCount();
if (DeviceCount > 0)
{
IsInit = true;
}
else
{
zkfp2.Terminate();
}
}
}
catch (Exception)
{
}
return IsInit;
}
/// <summary>
/// 打开识别器
/// </summary>
/// <returns></returns>
public bool OpenFinger()
{
try
{
int ret = zkfp.ZKFP_ERR_OK;
if (IntPtr.Zero == (mDevHandle = zkfp2.OpenDevice(DeviceCount - 1)))
{
return IsOpen;
}
if (IntPtr.Zero == (mDBHandle = zkfp2.DBInit()))
{
zkfp2.CloseDevice(mDevHandle);
mDevHandle = IntPtr.Zero;
return IsOpen;
}
RegisterCount = 0;
cbRegTmp = 0;
iFid = 1;
for (int i = 0; i < 3; i++)
{
RegTmps[i] = new byte[2048];
}
byte[] paramValue = new byte[4];
int size = 4;
zkfp2.GetParameters(mDevHandle, 1, paramValue, ref size);
zkfp2.ByteArray2Int(paramValue, ref mfpWidth);
size = 4;
zkfp2.GetParameters(mDevHandle, 2, paramValue, ref size);
zkfp2.ByteArray2Int(paramValue, ref mfpHeight);
FPBuffer = new byte[mfpWidth * mfpHeight];
IsOpen = true;
}
catch (Exception)
{
}
return IsOpen;
}
public void Close()
{
try
{
IsInit = false;
IsOpen = false;
RegisterCount = 0;
Thread.Sleep(1000);
zkfp2.CloseDevice(mDevHandle);
}
catch (Exception)
{
}
}
public static void FreeSensor()
{
try
{
zkfp2.Terminate();
//cbRegTmp = 0;
}
catch (Exception)
{
}
}
public string Compare()
{
string employeeid = "";
try
{
string selectSql = string.Format("select EmployeeId,FingerBuffer from P_EmployeeTab where FingerBuffer is not null", ERPInfo.Instance.UserId);
DataTable bufferDataTab = SqlHelper.ExecuteDataTable(selectSql);
if (bufferDataTab == null && bufferDataTab.Rows.Count == 0)
{
return employeeid;
}
else
{
foreach (DataRow row in bufferDataTab.Rows)
{
byte[] q_Finger = (byte[])row["FingerBuffer"];
int ret = zkfp2.DBMatch(mDBHandle, CapTmp, q_Finger);
if (0 < ret)
{
employeeid = row["EmployeeId"] + "";
break;
}
}
}
}
catch (Exception)
{
}
return employeeid;
}
}
}
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
namespace Lskj.Control.ZKFinger
{
/// <summary>
/// 提供转换:包括:Bitmap和BitmapImage相互转换。
///RenderTargetBitmap > BitmapImage
///ImageSource > Bitmap
///BitmapImage和byte[]相互转换。
///byte[] > Bitmap
/// </summary>
public class ImageTranslater
{
/// <summary>
/// Bitmap --> BitmapImage
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
{
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] bytes;
bytes = ms.GetBuffer();
BitmapImage bi = null;
try
{
bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = new MemoryStream(bytes);
bi.EndInit();
}
catch
{
Console.WriteLine("转换错误");
bi = null;
}
return bi;
}
// BitmapImage --> Bitmap
//public static Bitmap BitmapImageToBitmap(BitmapImage bitmapImage)
//{
// // BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));
// using (MemoryStream outStream = new MemoryStream())
// {
// BitmapEncoder enc = new BmpBitmapEncoder();
// enc.Frames.Add(BitmapFrame.Create(bitmapImage));
// enc.Save(outStream);
// Bitmap bitmap = new Bitmap(outStream);
// return new Bitmap(bitmap);
// }
//}
///// <summary>
///// byte数组转为bitmap
///// </summary>
///// <param name="byteArray"></param>
///// <returns></returns>
//public static BitmapImage ByteArrayToBitmap(byte[] byteArray)
//{
// BitmapImage bmp = null;
// try
// {
// bmp = new BitmapImage();
// bmp.BeginInit();
// bmp.StreamSource = new MemoryStream(byteArray);
// bmp.EndInit();
// }
// catch
// {
// bmp = null;
// }
// return bmp;
//}
///// <summary>
///// bitmap 转为byte数组
///// </summary>
///// <param name="bmp"></param>
///// <returns></returns>
//public byte[] BitmapImageToByteArray(BitmapImage bmp)
//{
// byte[] byteArray=null;
// try
// {
// Stream st = bmp.StreamSource;
// if (st != null && st.Length > 0)
// {
// st.Position = 0;
// using(BinaryReader br=new BinaryReader(st))
// {
// byteArray = br.ReadBytes((int)st.Length);
// }
// }
// }
// catch
// {
// byteArray = null;
// Console.WriteLine("转换失败");
// }
// return byteArray;
//}
/// <summary>
/// bitmapimage保存到指定路径的文件下
/// </summary>
/// <param name="bmp"></param>
/// <param name="filePath"></param>
public static void SaveBitmapImageIntoFile(BitmapImage bmp, string filePath)
{
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
encoder.Save(fileStream);
}
}
}
}
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Lskj.Control.ZKFinger
{
public class ZKFPCap
{
public const string ZKFPRI_NAME = @"ZKFPCap.dll";
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorInit")]
public static extern int sensorInit();
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorFree")]
public static extern int sensorFree();
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorOpen")]
public static extern IntPtr sensorOpen(int index);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorClose")]
public static extern int sensorClose(IntPtr handle);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorGetCount")]
public static extern int sensorGetCount();
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorGetVersion")]
public static extern int sensorGetVersion(byte[] version, int len);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorGetParameter")]
public static extern int sensorGetParameter(IntPtr handle, int paramCode);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorSetParameter")]
public static extern int sensorSetParameter(IntPtr handle, int paramCode, int paramValue);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorGetParameterEx")]
public static extern int sensorGetParameterEx(IntPtr handle, int paramCode, byte[] paramValue, ref int paramLen);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorSetParameterEx")]
public static extern int sensorSetParameterEx(IntPtr handle, int paramCode, byte[] paramValue, int paramLen);
[DllImport(ZKFPRI_NAME, EntryPoint = "sensorCapture")]
public static extern int sensorCapture(IntPtr handle, byte[] imageBuffer, int imageBufferSize);
}
}
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Lskj.Control.ZKFinger
{
class ZKFinger10
{
public const string ZKFPRI_NAME = @"ZKFinger10.dll";
public const int THRESHOLD_MIDDLE = 55; // 1:N recommendation threshold
public const int THRESHOLD_LOW = 35; // 1:1 recommendation threshold
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_INIT")]
public static extern IntPtr BIOKEY_INIT(int License, short[] isize, byte[] Params, byte[] Buffer, int ImageFlag);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_CLOSE")]
public static extern int BIOKEY_CLOSE(IntPtr Handle);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_SET_PARAMETER")]
public static extern int BIOKEY_SET_PARAMETER(IntPtr Handle, int paramCode, int paramValue);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_MATCHINGPARAM")]
public static extern int BIOKEY_MATCHINGPARAM(IntPtr Handle, int speed, int threshold);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_GETLASTQUALITY")]
public static extern int BIOKEY_GETLASTQUALITY();
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_GETLASTERROR")]
public static extern int BIOKEY_GETLASTERROR();
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_EXTRACT")]
public static extern int BIOKEY_EXTRACT(IntPtr Handle, byte[] PixelsBuffer, byte[] Template, int PurposeMode);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_GENTEMPLATE")]
public unsafe static extern int BIOKEY_GENTEMPLATE(IntPtr Handle, byte*[] Templates, int TmpCount, byte[] GTemplate);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_GENTEMPLATE_SP")]
public unsafe static extern int BIOKEY_GENTEMPLATE_SP(IntPtr Handle, byte[] Template1, byte[] Template2, byte[] Template3, int TmpCount, byte[] GTemplate);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_DB_ADD")]
public static extern int BIOKEY_DB_ADD(IntPtr Handle, int TID, int TempLength, byte[] Template);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_DB_DEL")]
public static extern int BIOKEY_DB_DEL(IntPtr Handle, int TID);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_DB_COUNT")]
public static extern int BIOKEY_DB_COUNT(IntPtr Handle);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_DB_CLEAR")]
public static extern int BIOKEY_DB_CLEAR(IntPtr Handle);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_IDENTIFYTEMP")]
public static extern int BIOKEY_IDENTIFYTEMP(IntPtr Handle, byte[] Template, ref int TID, ref int Score);
[DllImport(ZKFPRI_NAME, EntryPoint = "BIOKEY_VERIFY")]
public static extern int BIOKEY_VERIFY(IntPtr handle, byte[] Template1, byte[] Template2);
}
}