public static Neurotec.Images.NImage getNImageDataFromBytes(byte[] blob) { /* * openconn(); * string sql = "select IMGDATA from t_img where imgID=100"; * MySqlCommand comm = new MySqlCommand(sql,conn); * MySqlDataReader msr = comm.ExecuteReader(); * Byte[] blob = new Byte[(msr.GetBytes(2, 0, null, 0, int.MaxValue))]; * msr.GetBytes(2, 0, blob, 0, blob.Length); */ Neurotec.IO.NMemoryStream ms = new Neurotec.IO.NMemoryStream(blob); // System.IO.MemoryStream ms = new System.IO.MemoryStream(blob); Neurotec.Images.NImage img = Neurotec.Images.NImage.FromStream(ms); return(img); }
/* * int score; * private void OnVerifyCompleted(IAsyncResult r) * { * lock (locker) * { * * try * { * NBiometricStatus status = _biometricClient.EndVerify(r); * if (status == NBiometricStatus.Ok || status == NBiometricStatus.MatchNotFound) * { * //get matching score * score = _subject1.MatchingResults[0].Score; * // string msg = string.Format("Score of matched templates: {0}", score); * //msgLabel.Text = msg; * // MessageBox.Show(msg); * } * else MessageBox.Show(status.ToString()); * } * catch (Exception ex) * { * Utils.ShowException(ex); * } * } * * }*/ protected void Button1_Click(object sender, EventArgs e) { deleteresultshow(); NMatcher nm = new NMatcher(); OpenImageTemplate(faceView1, out _subject1); MySqlConnection conn = new MySqlConnection("server=localhost;database=test;uid=root;password=root"); conn.Open(); String sqlcommand = String.Format("select * from imgdata"); MySqlCommand cmd = new MySqlCommand(sqlcommand, conn); MySqlDataReader msr = cmd.ExecuteReader(); while (msr.Read()) { string id = (string)msr.GetValue(1); byte[] blob = (byte[])msr.GetValue(0); string name = (string)msr.GetValue(2); string gender = (string)msr.GetValue(3); DateTime bir = (DateTime)msr.GetValue(4); string birth = bir.ToShortDateString(); string phonenumber = (string)msr.GetValue(5);; Neurotec.Images.NImage img = ImageData.getNImageDataFromBytes(blob); NFace face = new NFace(); face.Image = img; NSubject subject = new NSubject(); subject.Faces.Add(face); // _biometricClient.BeginCreateTemplate(subject, OnCreationCompleted, subject); nle.CreateTemplate(subject); // Thread.Sleep(500); if (_subject1 != null && subject != null) { int score1 = nm.Verify(_subject1.GetTemplateBuffer(), subject.GetTemplateBuffer()); // _biometricClient.BeginVerify(_subject1,subject, OnVerifyCompleted, null); btlist.Add(new btnode(blob, score1, id, name, gender, birth, phonenumber)); } } conn.Close(); msr.Close(); int maxscore = 0; int temp = 0; string str = ""; for (int i = 0; i < btlist.Count; i++) { sqlcommand = "insert into resultshow(score,id,name,gender,birth,phonenumber,data) values(@score,@id,@name,@gender,@birth,@phonenumber,@data)"; cmd = new MySqlCommand(sqlcommand, conn); MySqlParameter[] param = new MySqlParameter[7]; param[0] = new MySqlParameter("@score", btlist[i].score); param[1] = new MySqlParameter("@id", btlist[i].id); param[2] = new MySqlParameter("@name", btlist[i].name); param[3] = new MySqlParameter("@gender", btlist[i].gender); param[4] = new MySqlParameter("@birth", btlist[i].birth); param[5] = new MySqlParameter("@phonenumber", btlist[i].phonenumber); param[6] = new MySqlParameter("@data", btlist[i].blob); for (int j = 0; j < param.Length; j++) { cmd.Parameters.Add(param[j]); } conn.Open(); try { cmd.ExecuteNonQuery(); } catch (System.Exception ex) { StreamWriter sw = new StreamWriter("C:\\myerror.txt", true, Encoding.Default); sw.Write(ex.Message); sw.Close(); //一旦发生错误程序就停止运行,等待用户发现 Console.Read(); } conn.Close(); conn.Dispose(); msr.Dispose();/* * if (btlist[i].score>maxscore) * { * maxscore = btlist[i].score; * temp = i; * }*/ // str += btlist[i].score + " "; } // MessageBox.Show(str); /* * sqlcommand = "insert into resultshow(score,data) values(@score,@data)"; * cmd = new MySqlCommand(sqlcommand, conn); * MySqlParameter[] param = new MySqlParameter[2]; * param[0] = new MySqlParameter("@score",btlist[temp].score); * param[1] = new MySqlParameter("@data", btlist[temp].blob); * for (int i = 0; i < param.Length; i++) * cmd.Parameters.Add(param[i]); * conn.Open(); * try * { * cmd.ExecuteNonQuery(); * } * catch (System.Exception ex) * { * StreamWriter sw = new StreamWriter("C:\\myerror.txt", true, Encoding.Default); * sw.Write(ex.Message); * sw.Close(); * //一旦发生错误程序就停止运行,等待用户发现 * Console.Read(); * } * * conn.Close(); * conn.Dispose(); * msr.Dispose(); */ Response.Redirect("Default4.aspx", false); }