我想通过检查图像的像素值来比较两个图像,看它们是否是相同的图像。 DB有一个表格,列中的图像保存为BLOB
类型。
我将图片上传到图片框,然后与DB一起检查以检索名为" CID"的列中的值。当图片框图像的像素值类似于来自DB的图像的像素值时。
代码在C#中使用MySql和VisualStudio。
但是,它提供了Parameter is not valid
我在这里做错了什么?任何帮助都将受到高度赞赏。
private void search_botton_Click_1(object sender, EventArgs e)
{
if (leftRadio.Checked == true)
{
try
{
string MyConnection = "datasource=127.0.0.1;port=3306;username=root;password=;database=ahbis";
string sql = "SELECT * FROM criminal";
MySqlConnection MyConn = new MySqlConnection(MyConnection);
MySqlCommand MyCommand = new MySqlCommand(sql, MyConn);
MySqlDataReader MyReader;
MyConn.Open();
MyReader = MyCommand.ExecuteReader();
while (MyReader.Read())
{
//byte[] should be converted to Bitmap
byte[] img_Byte = (byte[])(MyReader["palmHistogram_A_L"]);
Image img1_IMAGE = (Bitmap)((new ImageConverter()).ConvertFrom(img_Byte));
//img1 = new Bitmap(img1_IMAGE);
Bitmap img1 = (Bitmap)new ImageConverter().ConvertTo(img1_IMAGE, typeof(Bitmap[]));
img2 = new Bitmap(histogram_pictureBox.Image);
string img1_ref, img2_ref;
if (img1.Width == img2.Width && img1.Height == img2.Height)
{
for (int i = 0; i < img1.Width; i++)
{
for (int j = 0; j < img1.Height; j++)
{
img1_ref = img1.GetPixel(i, j).ToString();
img2_ref = img2.GetPixel(i, j).ToString();
if (img1_ref != img2_ref)
{
count2++;
flag = false;
break;
}
count1++;
}
}
if (flag == false)
MessageBox.Show("No matches found!");
else
MessageBox.Show("Match found!");
string cid = MyReader.GetString("CID");
textBox1.Text = cid;
}
else
MessageBox.Show("Something went wrong!");
}
MyConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
代码在开头也有以下部分;
Bitmap img1,img2;
int count1 = 0, count2 = 0;
bool flag = true;
答案 0 :(得分:-1)