Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 标记两幅图片之间的差异_C#_Colors_Bitmap - Fatal编程技术网

C# 标记两幅图片之间的差异

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

我写了一个小程序,比较了两个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# 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;
    }