我正在尝试将指纹保存到C#中的SQL Server数据库中。我正在使用zk4500指纹识别器。我可以扫描手指并创建模板。现在我被困在如何将这些扫描的指纹保存到数据库中。下面是创建模板的代码,请帮助我如何保存到数据库。
protected override void DefWndProc(ref Message m)
{
switch (m.Msg)
{
case MESSAGE_FP_RECEIVED:
{
try
{
MemoryStream ms = new MemoryStream();
//Template.Serialize(ms);
BitmapFormat.GetBitmap(g_FPBuffer, g_nWidth, g_nHeight, ref ms);
Bitmap bmp = new Bitmap(ms);
this.picFP.Image = bmp;
ms.Position = 0;
BinaryReader br = new BinaryReader(ms);
Byte[] bytes = br.ReadBytes((Int32)ms.Length);
txtStatus.Text = "IMAGE_READY";
int ret = 0;
int id = 0;
int score = 0;
int quality = 0;
if (g_IsRegister)
{
Array.Clear(g_RegTmp, 0, g_RegTmp.Length);
ret = ZKFinger10.BIOKEY_EXTRACT(g_biokeyHandle, g_FPBuffer, g_RegTmp, 0);
if (ret > 0)
{
Array.Copy(g_RegTmp, g_RegTmps[g_RegisterTimeCount++], ret);
// Get fingerprint quality
quality = ZKFinger10.BIOKEY_GETLASTQUALITY();
txtQuality.Text = quality.ToString();
txtPrompt.Text = string.Format("Still press finger {0} time", REGISTER_FINGER_COUNT - g_RegisterTimeCount);
if (g_RegisterTimeCount == REGISTER_FINGER_COUNT)
{
Array.Clear(g_RegTmp, 0, g_RegTmp.Length);
int size = 0;
unsafe
{
fixed (byte* Template1 = g_RegTmps[0])
{
fixed (byte* Template2 = g_RegTmps[1])
{
fixed (byte* Template3 = g_RegTmps[2])
{
byte*[] pTemplate = new byte*[3] { Template1, Template2, Template3 };
size = ZKFinger10.BIOKEY_GENTEMPLATE(g_biokeyHandle, pTemplate, 3, g_RegTmp);
}
}
}
}
if (size > 0)
{
ZKFinger10.BIOKEY_DB_ADD(g_biokeyHandle, ++g_RegisterCount, size, g_RegTmp);
txtPrompt.Text = string.Format("Register succeeded, fid={0}, totalCount={1}", g_RegisterCount, ZKFinger10.BIOKEY_DB_COUNT(g_biokeyHandle));
g_IsRegister = false;
}
else
{
txtPrompt.Text = "Register failed";
}
g_RegisterTimeCount = 0;
}
}
else
{
txtPrompt.Text = "Extract template failed";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
break;
default:
base.DefWndProc(ref m);
break;
}
}
答案 0 :(得分:0)
if (size > 0)
{
textbox1.Text=ZKFinger10.EncodeTemplate1(g_RegTmp); ///this code will genarate system64 string and store database field
ZKFinger10.BIOKEY_DB_ADD(g_biokeyHandle, ++g_RegisterCount, size, g_RegTmp);
txtPrompt.Text = string.Format("Register succeeded, fid={0}, totalCount={1}", g_RegisterCount, ZKFinger10.BIOKEY_DB_COUNT(g_biokeyHandle));
g_IsRegister = false;
}