我有多个由不同软件在多个文件夹中生成的标签。标签的大小相同,但它们的透明度标签不同。理想情况下它们是相同的,但是当我使用我的内部应用程序进行比较时,它会抛出错误,说它们不匹配。
我知道有人问过类似的问题,但它们与我的问题并不完全匹配。我需要使用 c# 实现相关算法。
我正在探索一些 API AForge.Net、ImageMagick。
直到现在我已经比较了字节
filename1 = Path.Combine(directory.ToString(), new1[i].ToString());
filename2 = Path.Combine(directory1.ToString(), new2[i].ToString());
using (Bitmap bm1 = new Bitmap(filename1))
{
using (Bitmap bm2 = new Bitmap(filename2))
{
// Make a difference image.
int wid = Math.Min(bm1.Width, bm2.Width);
int hgt = Math.Min(bm1.Height, bm2.Height);
Bitmap bm3 = new Bitmap(wid, hgt);
// Create the difference image.
bool are_identical = true;
Color eq_color = Color.White;
Color ne_color = Color.Red;
for (int x = 0; x < wid; x++)
{
for (int y = 0; y < hgt; y++)
{
//if (bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)))
if (bm1.GetPixel(x, y) != (bm2.GetPixel(x, y)))
{
//bm3.SetPixel(x, y, eq_color);
bm3.SetPixel(x, y, ne_color);
are_identical = false;
}
else
{
//bm3.SetPixel(x, y, ne_color);
//are_identical = false;
}
}
//I kept the code here before
}
if (!are_identical)
{
bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages" + new1[i]);
}
// Display the result.
//picResult.Image = bm3;
//bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages\" + new1[i]);
this.Cursor = Cursors.Default;
if ((bm1.Width != bm2.Width) || (bm1.Height != bm2.Height)) are_identical = false;
if (are_identical)
{
//richTextBox1.Text = string.Format("Images are identical", "\r\n");
sb.AppendLine("Image Name=" + new1[i] + " are identical at both folder");
}
else
{
//richTextBox1.Text = string.Format("Images are NOT MATCHING", "\r\n");
sb.AppendLine("Image Name=" + new1[i] + " are Not Matching at both folder");
}
//sb.AppendLine(f1.Name + ": " + (equal ? "Images are equal" : "Images are NOT equal"));
}
}
result.Add(sb.ToString());