使用Microsoft.VisualStudio.TestTools.UITesting的ImageComparer比较两个图像

时间:2014-11-30 12:41:16

标签: c# coded-ui-tests ui-testing

我需要使用ImageComparer.Compare(currentImage,savedImage,tol,out imageDiff)来比较两个图像;

我以下面的方式实现了代码,但结果总是得到假。请在我出错的地方帮忙。

private static Image CompareImages(Image savedImage, Image currentImage, string referenceImagesFolder)
        {
            const int borderWidth = 4;
            var rectangle1 = new Rectangle(new Point(borderWidth, borderWidth),
                new Size(savedImage.Width - borderWidth * 2, savedImage.Height - borderWidth * 2));
            var rectangle = rectangle1;
            var tol = new List<ToleranceRectangle>
            {
                new ToleranceRectangle()
                {
                    Rectangle = rectangle,
                    Difference = new ColorDifference()
                }
            };
            Image imageDiff;

            var compareResult = ImageComparer.Compare(currentImage, savedImage, tol, out imageDiff);
            if (!compareResult)
            {
               return imageDiff;
            }
            return null;

0 个答案:

没有答案