Match bitmap image from server via BiometricSDK with another bitmap image? - c#

I have stored a bitmap image in a server and want to do matching through BiometricSDK with another image that I select. I have got no idea how to solve it. Here is my current code.
//Make finger print image get through SDK process
Boolean result = true;
var fprintsdk = new BiometricsSDK.FingerPrint.CFingerPrint();
var fprintresult = new BiometricsSDK.FingerPrint.CFingerPrint();
//get finger print image
fprintsdk.setFingerPrintImage(fprintsdk.getFingerPrintImage());
fprintresult.setFingerPrintImage(fprintresult.getFingerPrintImage());
FPrintImg.Image = fprintresult.getFingerPrintImageDetail();
FPrintImg.SizeMode = PictureBoxSizeMode.StretchImage;
//Open window to select finger print image
var open = new OpenFileDialog();
open.FileName = string.Empty;
open.Filter = "BMP|*.bmp"; //open text file as default
open.Multiselect = false;
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bmp = (Bitmap) Image.FromFile(open.FileName); //select image and store out
string Constr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source = BankServer.mdb";
OleDbConnection Conn = new OleDbConnection(Constr);
Conn.Open();
string sFingerPrint = "Select * from Server Where Hash = '" + ccinfo + "'"; //get data from server
OleDbCommand cmd1 = new OleDbCommand(sFingerPrint, Conn);
OleDbDataReader read1 = cmd1.ExecuteReader();
while (read1.Read()) //loop all data
{
//(Problem Stuck over Here)
if (read1["FingerPrint"].GetType() == bmp) //Comparison text file and database
{
Messagebox.show("Well Done");
}
}
}

I don`t know what SDK you are using. Therefore, you needs to search how to generate a template from this two images and match the two templates. Biometric match is not done with images directly but with templates.
If you tell us what SDK you are using maybe I can answer it better.

Related

How to display image into picture box using image path in database

How can I retrieve image into picture box using image path in database? Before this I retrieve from shared folder but its make my system slow when loading image. Then I changes the method wheres I want to retrieve image into picture box using image path that stored in MSSQL database. Hopefully it not slow down my system. Anyone please help me. Here is my code but not work to retrieve image.
private void textBoxEmplNo_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (textBoxEmplNo.Text != "")
{
string selectSql = "select a.name, a.empno, a.workno, a.icnum, a.passport, a.deptno, a.section, a.designation, b.path from m_employee a inner join m_emp_photo b on b.empno=a.empno where a.empno= #empno";
SqlCommand cmd = new SqlCommand(selectSql, con);
cmd.Parameters.AddWithValue("#empno", textBoxEmplNo.Text);
bool isDataFound = false;
try
{
con.Open();
using (SqlDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
isDataFound = true;
textBoxWorkNo.Text = (read["workno"].ToString());
textBoxName.Text = (read["name"].ToString());
textBoxICPass.Text = (read["icnum"].ToString());
textBoxPassport.Text = (read["passport"].ToString());
textBoxDept.Text = (read["deptno"].ToString());
textBoxSection.Text = (read["section"].ToString());
textBoxDesignation.Text = (read["designation"].ToString());
pictureBox1.Image = Image.FromFile("#path");
}
}
pictureBox1.Image = Image.FromFile("" + read["path"].ToString());
pictureBox1.SizeMode=System.Windows.Forms.PictureBoxSizeMode.StretchImage;

How can I display my picture in postgres database with c#?

I can save in my postgres databes my picture which is in picturebox.
but after How can I display my picture in postres database with c# ?
FileStream fs = new FileStream(resimPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] resim = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
PostgisBaglan.Open();
strEksenCizgisiUpdate = "INSERT INTO reismDatabase(resimismi,resimkendi) values('resim3','"+resim+"');";
NpgsqlCommand EksenCizgisiUpdateCommand = new NpgsqlCommand(strEksenCizgisiUpdate, PostgisBaglan);
EksenCizgisiUpdateCommand.ExecuteNonQuery();
PostgisBaglan.Close();
openFileDialog1.Filter = "Jpeg Dosyası (*.jpg)|*.jpg|Gif Dosyası (*.gif)|*.gif|Png Dosyası (*.png)|*.png|Tif Dosyası (*.tif)|*.tif";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
resimPath = openFileDialog1.FileName.ToString();
}
You can't display an image "from the database".
In your application, you need to read the image from the database, and then display it.
Assuming your table looks like this:
create table reismDatabase (
resimismi text, -- or some variant
resimkendi bytea
);
This would be code to read the table contents into a picture object:
NpgSqlCommand cmd = new NpgsqlCommand("select resimismi, resimkendi from reismDatabase",
conn);
NpgsqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string photoName = reader.GetString(0);
Byte[] photoContents = (Byte[])Reader.GetValue(1);
Image photo;
if (photoContents != null)
{
using (Stream st = new System.IO.MemoryStream(photoContents))
photo = Image.FromStream(st);
}
}
reader.Close();
From there, you can assign photo to your pictureBox.Image.
I found my solution.
Postgisconn.Open();
str= "INSERT INTO testimage (id, image) VALUES (1, lo_import('C://test.jpg'));";
NpgsqlCommand cmmnd= new NpgsqlCommand(str, Postgisconn);
cmmnd.ExecuteNonQuery();
Postgisconn.Close();
I save with this query my image in my database.
pictureBox1.Image.Dispose();
Postgisconn.Open();
str= "SELECT lo_export(testimage.image, 'C://outputimage.jpg') FROM testimage WHERE id =1;";
NpgsqlCommand cmmnd= new NpgsqlCommand(str, Postgisconn);
cmmnd.ExecuteNonQuery();
Postgisconn.Close();.
pictureBox1.Image = Image.FromFile("C://outputimage.jpg");
with this query , I display my database image to picturebox.
Thank all of you who answer to my question.

Saving multiple Images at once to the database with a FileUpload Control

I am working on a company Blog site, and when a user is making a post, they can add an image from their computer to the post. I used a FileUpload control to do this, and it works great. However, I am trying to change the functionality to allow the user to select and upload multiple images in one post, and I am running into some issues. I have set the 'allow multiple' property to 'true', however once multiple images are selected into the control (Image URLs get separated by a comma) and the post button is clicked, only one of the images is inserted into the database, but it is inserted as many times as images there are, and only that one image is displayed on the blog post. So if I try to add three different images, it inserts three instances of the first image into the database. The code corresponding to the the FileUpload in my onClick function is below:
if (imageUpload.HasFile == true)
{
SqlCommand maxMessId = new SqlCommand("SELECT Max(MessageID) FROM BlogMessages", conn);
lastMessageID = Convert.ToInt32(maxMessId.ExecuteScalar());
foreach (var uploadedFile in imageUpload.PostedFiles)
{
SqlCommand cmdInsertImage = new SqlCommand("INSERT INTO BlogImages(Image, MessageID) VALUES (#Image, #MessageID)", conn);
cmdInsertImage.Parameters.AddWithValue("#Image", SqlDbType.Image).Value = imageUpload.FileBytes;
cmdInsertImage.Parameters.AddWithValue("#MessageID", lastMessageID);
cmdInsertImage.ExecuteNonQuery();
}
}
I am thinking the issue could be with:
cmdInsertImage.Parameters.AddWithValue("#Image", SqlDbType.Image).Value = imageUpload.FileBytes;
If that is getting the file bytes for only one image.. I am not sure how to get the filebytes for both files. The image column in my BlogImages table is of the type Image.
Any suggestions are much appreciated!
Are you sure that you're working on the right way ?????PostesFiles are the list of file and each one has it own properties you need to read from there.....nothing else
Here a simples examples
For Each xx In fp.PostedFiles
xx.InputStream
xx.ContentLength
xx.FileName
Next
Where those properties upon expose Inputstrem a stream of the image,ContenteLenght it lenght, Filename the filename of the images.So when you pass the imageupload.FileBytes is not the correct way to achive your goal.You have to read the stream and return a bytearray to save the data withing your sql server.Nothing else i hope it could help you to solve your issue.
UPDATE*
Assume that you're into the foreach loop for each single file you have to setup its own bytearray
MemoryStream ms = new MemoryStream();
file.PostedFile.InputStream.CopyTo(ms);
var byts = ms.ToArray();
ms.Dispose();
then
change your insert statement like this
cmdInsertImage.Parameters.AddWithValue("#Image", SqlDbType.Image).Value = byts;
not tested but it should solve the issue.
UPDATE 2
if (test.HasFiles) {
StringBuilder sb = new StringBuilder();
foreach (void el_loopVariable in test.PostedFiles) {
el = el_loopVariable;
sb.AppendLine("FILENAME:<B>" + el.FileName.ToString + "</B><BR/>");
MemoryStream ms = new MemoryStream();
el.InputStream.CopyTo(ms);
byte[] byts = ms.ToArray;
ms.Dispose();
sb.AppendLine(string.Join(";", byts));
sb.AppendLine("<br/<br/>");
byts = null;
}
LitResponse.Text = sb.ToString;
}
I think the issue is that in your for each loop, you're stepping through the posted files, but you're still just using ImageUpload.FileBytes each time, which I expect would be returning the same thing each time.
I'm not super familiar with the file upload control, but maybe you can use the ContentLength property of your uploaded file object to index into the byte array returned by ImageUpload.FileBytes (assuming that array contains each of the multiple files).
protected void btnSubmit_Click(object sender, EventArgs e)
{
string strImageName = txtImage.Text.ToString(); //to store image into sql database.
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
// Create SQL Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Pictures(ID,ImageName,Image)" +
" VALUES (#ID,#ImageName,#Image)";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
//retrieve latest ID from tables which was stored in session.
int ID = Convert.ToInt32(System.Web.HttpContext.Current.Session["ID"].ToString());
SqlParameter ID = new SqlParameter
("#ID", SqlDbType.Int, 5);
ID.Value = (Int32)ID;
cmd.Parameters.Add(ID);
SqlParameter ImageName = new SqlParameter
("#ImageName", SqlDbType.VarChar, 50);
ImageName.Value = strImageName.ToString();
cmd.Parameters.Add(ImageName);
SqlParameter UploadedImage = new SqlParameter("#Image", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);
conn.Open();
int result = cmd.ExecuteNonQuery();
conn.Close();
if (result > 0)
lblMessage.Text = "File Uploaded";
lblSuccess.Text = "Successful !";
}}

Saving and retrving image from mysql

In C#, I am trying to save and load an image. I am saving it into a mysql database (type longblob) and trying to load it back into an picture box. The problem i keep getting is the error "Parameter is not valid", see code below
ConnectionClass Sqlconnection = new ConnectionClass();
Sqlconnection.ConnectionOpen();
OdbcCommand cmd = new OdbcCommand("Insert into pictest(pic) values('"+ Encoding.Unicode.GetBytes(richTextBox1.Rtf) + "')", Sqlconnection.connection);
int num = cmd.ExecuteNonQuery();
MessageBox.Show(num + " Rows inserted ");
Sqlconnection.ConnectionClose();
OdbcDataReader rd = null;
try
{
Sqlconnection.ConnectionOpen();
string query = "select * from pictest where id = 1";
cmd = new OdbcCommand(query, Sqlconnection.connection);
rd = cmd.ExecuteReader();
if (rd.Read())
{
byte[] bytes = (byte[])rd[1];
ImageConverter converter = new ImageConverter();
pictureBox1.Image = Image.FromStream(new MemoryStream(bytes)); <--Parameter is not valid
pictureBox1.Refresh();
pictureBox1.Image = Encoding.Unicode.GetString(bytes);
}
Sqlconnection.ConnectionClose();
rd.Close();
}
catch (Exception asd)
{
MessageBox.Show("Problem " + asd.Message);
Sqlconnection.ConnectionClose();
if (rd != null)
{
rd.Close();
}
}
what exact is the problem? Is the image not saving correctly? it should be as it is saving to a longblob. The record for the image says System.Byte[]
you should be able to inspect (via the debugger) the values inside OdbcDataReader before trying to cast the first field to byte[]. Take a look at what type is actually stored in the OdbcDataReader
Using SELECT * is problematic performance wise. It also leaves your rd[1] up for interpretation. If the order of columns ever changes, your code could break. Use rd["your_column_name"] to access the values. As of right now I can't tell if index 1 is correct due to the SELECT * and non-named indexing into the Items array.
First of all why you need to store image in MySql?
Why not in physical drive? If its not a crucial data go for saving it in physical drive.
However, here is code to retrieve:
public byte [] getImage(int imageNumber)
{
string strSql = "SELECT * FROM File";
DataSet ds = new DataSet("Image");
OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql,this._objConn);
OdbcCommandBuilder objCommand = new OdbcCommandBuilder(tempAP);
tempAP.Fill(ds,"Table");
try
{
this._objConn.Open();
byte [] buffer = (byte [])ds.Tables["Table"].Rows[imageNumber]["Data"];
return buffer;
}
catch{this._objConn.Close();return null;}
finally{this._objConn.Close();}
}
Courtesy:
http://www.codeproject.com/Articles/6750/Storing-Images-in-MySQL-using-ASP-NET
For physical drive
http://www.codeproject.com/Articles/2113/C-Photo-Album-Viewer

C# getting file path of an Image in an imagebox

I have a database with a table "product" in it and in this table there as a field called "PackingPicture" od type Image. I have a form in which I load a record details including the image.
Is there a way to also load the image file path to a textbox?
The reason I want to do this is to that I want to be able to updte the record using sql update query in this form. I wnat to user to be able to update any data filed in this form whether it's the image or not. Is there a way to get the file path upon retrieving the image from the database?
alternatively, if there is a way to save the picture itself without the file path I would be pleased to know.
My code for retrieving data:
public void getData(string brand, string product)
{
DataTable dt = new DataTable();
Connection c = new Connection();
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM tblProduct WHERE productNumber = #Product and brandNumber=#brand", c.con);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
c.con.Open();
sqlCmd.Parameters.AddWithValue("#brand", brand);
sqlCmd.Parameters.AddWithValue("#Product", product);
sqlDa.Fill(dt);
SqlDataReader dr = sqlCmd.ExecuteReader();
if (dt.Rows.Count > 0)
{
comboBox2.Text = dt.Rows[0][0].ToString();
//Where ColumnName is the Field from the DB that you want to display
textBox1.Text = dt.Rows[0][1].ToString();
textBox2.Text = dt.Rows[0][2].ToString();
}
while (dr.Read())
{
byte[] img = (byte[])(dr["PackingPicture"]);
if (img == null)
pictureBox1.Image = null;
else
{
MemoryStream stream = new MemoryStream(img);
pictureBox1.Image = System.Drawing.Image.FromStream(stream);
}
}
c.con.Close();
}
Is there a way to get the file path upon retrieving the image from the
database?
If you haven't saved the file path, you cannot retrieve what is not present.
Alternatively, if there is a way to save the picture itself without
the file path
after assigning to the picturebox, you can save the picture from picture box like
pictureBox1.Image.Save("yourfilepath", yourformat);
or you can save it through the stream
using(MemoryStream stream = new MemoryStream(img))
{
FileStream fs = File.OpenWrite("yourfile");
fs.Write(stream.ToArray());
fs.Close();
}
There is no file path because the image exists in memory and in the database, but not in any particular image file. Therefore you need to save it, which you can do like this:
pictureBox1.Image.Save("c:\\path\\to\\image.gif", ImageFormat.Gif); // you have to know your image format

Categories

Resources