1
我正在创建图像比较(图像存在于目录中)基于Web的应用程序。它将特定目录中的图像与提供的图像进行比较。它会将每个图像与匹配的百分比进行比较,但不会显示来自相关目录的图像,即使我已将图像网址也提供给该图像。当我写入response.write时,它会显示与该匹配图像匹配的百分比,但不显示图像。 我写的代码为如下:在按钮单击事件中使用图像控件显示图像
protected void btnnew_Click(object sender, EventArgs e)
{
Bitmap searchImage;
try
{
//Image for comparing other images that are exists in directory
searchImage = new Bitmap(@"D:\kc\ImageCompare\Images\img579.jpg");
}
catch (ArgumentException)
{
return;
}
string dir = "D:\\kc\\ImageCompare\\Images";
DirectoryInfo dir1 = new DirectoryInfo(dir);
FileInfo[] files = null;
try
{
files = dir1.GetFiles("*.jpg");
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("Bad directory specified");
return;
}
double sim;
foreach (FileInfo f in files)
{
sim = Math.Round(GetDifferentPercentageSneller(searchImage, new Bitmap(f.FullName)), 3);
if (sim >= 0.95)
{
Image1.ImageUrl = dir + files[0];
Image2.ImageUrl = dir + files[1];
Response.Write("Perfect match with Percentage" + " " + sim + " " + f);
Response.Write("</br>");
}
else
{
Response.Write("Not matched" + sim);
}
}
}