I am trying to compare two images by using picture box, but I got a problem: How can I pass the selected picture name as a parameter to a function as a string?
I save picture path and name as a string name1 and string name2, but I got a problem when I pass them as parameters.
Below is my code. Please tell me where I am wrong.
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Title = "Select User Profile Image";
ofd1.Filter = "Image File(*.png;*.jpg;*.bmp;*.gif)|*.png;*.jpg;*.bmp;*.gif";
if (ofd1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(ofd1.FileName);
string name1 = ofd1.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
Compare(name1,name2);
}
public void Compare(string bmp1, string bmp2, byte threshold = 3)
{
Bitmap firstBmp = (Bitmap)Image.FromFile(bmp1);
Bitmap secondBmp = (Bitmap)Image.FromFile(bmp2);
firstBmp.GetDifferenceImage(secondBmp, true);
string result = string.Format("Difference: {0:0.0} %", firstBmp.PercentageDifference(secondBmp, threshold) * 100);
}