我正在尝试按像素比较两个图像。我在谷歌上搜索过位图,但我并不清楚。
我的代码显示错误Parameter is not valid
。
我试过这个;
var a = new Bitmap(imageurl);
但它不起作用。
我也参考这个网站进行图像比较:
http://www.c-sharpcorner.com/uploadfile/prathore/image-comparison-using-C-Sharp/
我试过的:
但在这条线上显示错误parameter is not valid
。
var img1 = new Bitmap(fileone);
var img2 = new Bitmap(filetwo);
我在这两个变量中有这样的存储路径,
fileone=C:\image\a.jpg:
filetwo=c:\image\b.jpg;
var img1 = new Bitmap(fileone);
var img2 = new Bitmap(filetwo);
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++;
}
// progressBar1.Value++;
}
if (flag == false)
Response.Write("Sorry, Images are not same , " + count2 + " wrong pixels found");
else
Response.Write(" Images are same , " + count1 + " same pixels found and " + count2 + " wrong pixels found");
}
else
Response.Write("can not compare this images");
this.Dispose();