如何在C#中将Digital Persona的指纹序列化并保存到数据库中

时间:2015-09-03 19:51:26

标签: c# fingerprint

我为我的digitalPersona设备下载了一个注册示例代码供我们使用。它可能已经注册并验证指纹,但问题是它将指纹.fpt文件保存在文件夹中。我想将它保存在数据库中。

我无法序列化FMD对象类型的指纹,

private void OnCaptured(CaptureResult captureResult)
{

    try
    {
        //check capture quality and throw an error if bad
        if (!_sender.CheckCaptureResult(captureResult)) return;

        SendMessage(Action.SendMessage, "la huella se capturo");

        DataResult<Fmd> resultConversion = FeatureExtraction.CreateFmdFromFid(captureResult.Data, Constants.Formats.Fmd.ANSI);
        if (captureResult.ResultCode != Constants.ResultCode.DP_SUCCESS)
        {
            _sender.Reset = true;
            throw new Exception(captureResult.ResultCode.ToString());
        }

        if (count == 0)
        {
            indiceDr = resultConversion.Data;
            XmlSerializer xml = new XmlSerializer(resultConversion.GetType());
            StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);
            xml.Serialize(writer,resultConversion);
            count += 1;
            SendMessage(Action.SendMessage, "Ahora coloca tu pulgar en el lector");
            SendMessage(Action.SendMessage, "gethashcode = "+sb.ToString());
        }
        else if (count == 1)
        {
            pulgarDr = resultConversion.Data;
            count += 1;
            SendMessage(Action.SendMessage, "Ahora coloca cualquier dedo en el lector");
        }
        else if (count == 2)
        {
            AnyFinger = resultConversion.Data;
            Fmd[] fmds = new Fmd[2];
            fmds[0] = indiceDr;
            fmds[1] = pulgarDr;

            //Verificar la documentacion del SDK
            int thresholdScore = DPFJ_PROBABILITY_ONE * 1 / 10000;

            IdentifyResult identifyResult = Comparison.Identify(AnyFinger,0,fmds, thresholdScore, 2);
            if (identifyResult.ResultCode != Constants.ResultCode.DP_SUCCESS)
            {
                _sender.Reset = true;
                throw new Exception(identifyResult.ResultCode.ToString());
            }

            SendMessage(Action.SendMessage,"Resultado de la identificación " + identifyResult.Indexes.Length.ToString());
            SendMessage(Action.SendMessage, "coloca el indice" );
            count = 0;
        }
    }
    catch (Exception ex)
    {
        SendMessage(Action.SendMessage, "Error" + ex.Message);
    }
}

2 个答案:

答案 0 :(得分:2)

您可以将XML序列化为:

tempFingerPrint = Fmd.SerializeXml(resultConversion.Data);

答案 1 :(得分:0)

好吧,我建议您以byte []格式导入和导出Fmd数据。

  

Fmd>获取字节[]>将byte []转换为base64

然后

  

base64>解码为字节[]>然后导入到Fmd

我的意思是C#在Java中导出和导入。 导出(C#)

Fmd fmd = resultConversion.Data;    
string base64Fmd = Convert.ToBase64String(fmd.Bytes)

导入(Java)

byte[] bFmd = Base64.getDecoder().decode(base64Fmd.getBytes("UTF-8"));    
Fmd fmd = UareUGlobal.GetImporter().ImportFmd(bytes1, Fmd.Format.ANSI_378_2004, Fmd.Format.ANSI_378_2004)

我使用技术,因为在Java库SerializeXml中找不到函数DeserializeXmldpuareu.jar
因此,这是我发现导入和导出Fmd的唯一方法。
但是,

  

这不会限制您使用Java还是C#,并且您可以将两者结合使用