C# 标记两幅图片之间的差异
我写了一个小程序,比较了两个png,并保存了其中一个和两张图片之间的显著差异C# 标记两幅图片之间的差异,c#,colors,bitmap,C#,Colors,Bitmap,我写了一个小程序,比较了两个png,并保存了其中一个和两张图片之间的显著差异 class Program { static void Main(string[] args) { string a = @"C:\Users\Florian\Desktop\Projects\C# selbst\Compare\Compare\bild1.jpg"; string b = @"C:\Users\Florian\Desktop\Projects\C# s
class Program
{
static void Main(string[] args)
{
string a = @"C:\Users\Florian\Desktop\Projects\C# selbst\Compare\Compare\bild1.jpg";
string b = @"C:\Users\Florian\Desktop\Projects\C# selbst\Compare\Compare\bild2.jpg";
Bitmap bl = new Bitmap(@a);
Bitmap br = new Bitmap(@b);
bool gleich = true;
if (bl.Size != br.Size)
{
gleich = false;
}
else
{
for (int x = 0; x < bl.Width; x++)
{
for (int y = 0; y < bl.Height; y++)
{
if (bl.GetPixel(x, y) != (br.GetPixel(x, y)))
{
gleich = false;
br.SetPixel(x, y, System.Drawing.Color.Red);
}
}
}
}
br.Save(@"C:\Users\Florian\Desktop\myBitmap.png", ImageFormat.Png);
if (gleich)
{
Console.WriteLine("gleich");
}
else
{
Console.WriteLine("unterschiedlich");
}
Console.ReadLine();
}
}
现在它可以正常工作了,谢谢:)由于压缩方案的原因,您正在使用的jpg源(与您的问题相反)往往会有很多细微的差异。尝试使用实际的png源代码来查看比较代码的工作情况。。!当你高兴并且发现它太慢时,你可能想要研究你正在使用的jpg源(与你的问题相反),由于压缩方案的原因,会有很多微小的差异。尝试使用实际的png源代码来查看比较代码的工作情况。。!当你高兴的时候,发现它太慢了,你可能想学习
private static bool TestPixel(Color c1, Color c2)
{
int toleranz = 5;
int rot = Math.Abs(c1.R - c2.R);
int grün = Math.Abs(c1.G - c2.G);
int blau = Math.Abs(c1.B - c2.B);
if (rot > toleranz || blau > toleranz || grün > toleranz)
return true;
return false;
}