我想比較兩個圖像,看看他們是通過檢查圖像的像素值相同的圖像。 DB有一個表格,其中的圖像保存爲BLOB
類型。如何解決「參數無效」異常
我將圖片上傳到圖片框中,然後使用數據庫檢查圖片,以檢索圖片框圖片的像素值與來自數據庫的圖片的像素值相似時名爲「CID」的列中的值。
該代碼是在使用MySQL和VisualStudio的C#。
然而,它給人的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 =(位圖)tc.ConvertFrom(img_Byte); –
難道你有看這裏https://stackoverflow.com? /問題/ 629955 /參數 - 不合法的異常加載系統繪圖圖像根據您的鏈接(S)的域/ URL –