从winForm pictureBox中的sql server数据VarBinary(Max)中检索指纹

时间:2017-02-27 16:48:37

标签: c# sql-server

我正在使用secugen指纹识别器和sdk ...使用sdk我能够在运行时扫描指纹,匹配,验证并在pictureBox中显示指纹图像..但是无法保存在数据库中...我的代码在数据库中保存指纹.. 这是插入代码

 private void BtnVerify_Click(object sender, EventArgs e)
        {
            Int32 iError;
            bool matched1 = false;
            bool matched2 = false;
            SGFPMSecurityLevel secu_level;

            secu_level = (SGFPMSecurityLevel)comboBoxSecuLevel_V.SelectedIndex;

            iError = m_FPM.MatchTemplate(m_RegMin1, m_VrfMin, secu_level, ref matched1);
            iError = m_FPM.MatchTemplate(m_RegMin2, m_VrfMin, secu_level, ref matched2);

            if (iError == (Int32)SGFPMError.ERROR_NONE)
            {
                if (matched1 & matched2)
                {
                    StatusBar.Text = "Verification Success";
                    //string name = "sumi";
                    SqlConnection con = new SqlConnection("Data Source=HP; user=sa; password=Admin1; Initial Catalog=schoolmanagement; Integrated Security=True");
                    string qry = "INSERT into teacher_fingerprint (teacher_id,name,teacher_fingerprints)values (@teacher_id,@name,@teacher_fingerprints)";
                    SqlCommand cmd = new SqlCommand(qry, con);
                    MemoryStream stream = new MemoryStream();

                    pictureBoxV1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] pic = stream.ToArray();
                    con.Open();
                    cmd.Parameters.AddWithValue("@teacher_id", comboBox2.Text);
                    cmd.Parameters.AddWithValue("@name", textBox2.Text + " " + textBox3.Text);
                    //cmd.Parameters.AddWithValue("@teacher_fingerprints", m_VrfMin);
                    cmd.Parameters.AddWithValue("@teacher_fingerprints",pic);
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                else
                {
                    StatusBar.Text = "Verification Failed";
                }
            }
            else
                DisplayError("MatchTemplate()", iError);
        }

这是我的DrawImage函数

 private void DrawImageImg(Byte[] imgData, PictureBox picBox)
        {
            int colorval;
            Bitmap bmp = new Bitmap(m_ImageWidth, m_ImageHeight);
            picBox.Image = (Image)bmp;

            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    colorval = (int)imgData[(j * m_ImageWidth) + i];
                    bmp.SetPixel(i, j, Color.FromArgb(colorval, colorval, colorval));
                }
            }
            picBox.Refresh();
        }

这是我的数据库..我不知道这个指纹二进制文件是否有效? enter image description here

我试图在pictureBox中选择指纹数据,但它不起作用 它给出了drawImage函数中的索引错误 这是我的选择代码

     m_RegMin5 = new Byte[400];

if (iError == (Int32)SGFPMError.ERROR_NONE)
                    {
                      DrawImage(fp_image, pictureBox1);
                      StatusBar.Text = "Device Message: Finger On";

                      SqlConnection conn = new SqlConnection(@"Data Source=HP; user=sa; password=Admin1; Initial Catalog=schoolmanagement; Integrated Security=True");
                      string query = "select teacher_fingerprints from teacher_fingerprint where teacher_id=2 ";
                      SqlCommand cmd = new SqlCommand(query, conn);
                      conn.Open();
                      m_RegMin5 = cmd.ExecuteScalar() as byte[];
                      DrawImageImg(m_RegMin5,pictureBox2);
                    }                      
                    else
                     {
                      DisplayError("GetImage()", iError);
                        }

0 个答案:

没有答案