【发布时间】:2018-02-26 09:26:25
【问题描述】:
我想通过检查图像的像素值来比较两张图像以查看它们是否是相同的图像。 DB 有一个表,其中有一列图像保存为BLOB 类型。
我将图像上传到图片框中,然后在图片框图像的像素值与数据库中图像的像素值相似时,使用数据库检查它以检索名为“CID”的列中的值。
代码在 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;
【问题讨论】:
-
哪一行得到异常?
-
@AnkitVijay - 它的“'System.ArgumentException'发生在 System.Drawing.dll 行中;位图 img1 = (Bitmap)tc.ConvertFrom(img_Byte);
标签: c# mysql visual-studio image-processing