How to compare two images?

前端 未结 3 528
误落风尘
误落风尘 2020-12-02 02:37
public void winCheck()
{
    if (button1.Image == img1)
    {
        w1 = \"P2\";
        button1.Image = new Bitmap(@\"win_cross.png\");
        button2.Image = ne         


        
3条回答
  •  眼角桃花
    2020-12-02 03:12

    Your code doesn't work because you are comparing the variables pointing to the images (i.e. in memory address) not the image data (pixels).

    See ImageComparer.Compare method. Has overloads to specify tolerance. It is available since VS2012.

    https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.imagecomparer.compare.aspx

提交回复
热议问题