【问题标题】:How to solve "Parameter not valid" exception如何解决“参数无效”异常
【发布时间】: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


【解决方案1】:

我建议转换为 base64 字符串会更容易比较。 请参阅下面的我的网站链接,它可能会帮助您将图像转换为 Base64

希望对你有所帮助。

my Website link here.

【讨论】:

  • 根据您的链接的域/URL 与您的用户名相同或包含您的用户名,您似乎已链接到您自己的网站。如果您这样做,您必须披露它是您的网站。如果您不透露它是您自己的网站,它通常被视为垃圾邮件。请参阅:What signifies "Good" self promotion?How to not be a spammer
  • 这实际上如何解决 OP 询问的问题?
  • 我不确定它在这里是否真的有帮助。而且我还没有尝试过,但我认为不是使用像素进行比较。为什么不将其转换为字符串并进行比较。这样比较起来会更容易。
  • @RegieBaquero - 我认为你没有理解这里代码的目的。是图像的特征提取,所以生成了直方图图像,需要看图像的内容是否相同,这就是使用像素的原因。我不想检查我添加到图片框中的图像是否已经保存在数据库中。
  • @AaaliaSajana - 我现在明白了。糟糕的是,我对代码的唯一目的完全视而不见,最终比较了实际图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-17
  • 1970-01-01
  • 2011-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多