Image Processor

The ImageProcessor is a tool used to compare two images. The main methods are as follows:

Check our best practices article related with our suggestions related with the Image Processor.

AreEqual

Compare if two images are the same. Example:

ImageProcessor.AreEqual("image1.png", "image2.png");

Contains

Search if the entire image contains the image fragment.

ImageProcessor.Contains("EntireImage.png", "ImageFragment.png");

The algorithm tolerates a certain level of difference between the images. The threshold parameter handles the tolerance level. The default value can be reduced to make it more permissive or increased to make it more strict.

Which is the best image format to use with the Image Processor? We recommend it to use in this order:

  1. Bitmap (.bmp): This is the most reliable format because the image is not compressed. If the file size of the images does not matter, we highly recommend doing the comparison with Bitmap images. Also, with Bitmap images, you can convert to any other image format if need it.

  2. Tag Image File Format (.tiff): This allows raw, lossy, and lossless compression, and the quality of the image has a priority against the file size. Usually used for scanning/printing documents. If you don't want to use Bitmap, the TIFF images are your way to go.

  3. Portable Network Graphics (.png): Offers the same compression capabilities as .tiff, excluding raw, has better compatibility, and focuses on the file size.

  4. Joint Photographic Experts Group (.jpeg/.jpg): This format allows lossy compression to reduce the file size considerably. Avoid this format for text comparisons. Only use this if one of the above is not available, or you already had the baseline images with this format.

The Graphics Interchange Format (.gif) image format is not currently supported to compare images.

Save Image

Remember that you need to specify the ImageFormat when saving a Bitmap, here is an example using UiPlayer:

Bitmap myFile = MyPageObject.MyControl.GetScreenshot();
myFile.Save("MyFile.tiff", ImageFormat.Tiff);

When you only specify the name without ImageFormat, the Bitmap will be saved as a PNG image regardless of the extension.

Last updated