Class ImageComparisonUtil


  • public final class ImageComparisonUtil
    extends java.lang.Object
    Tools for the ImageComparison object.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float getDifferencePercent​(java.awt.image.BufferedImage img1, java.awt.image.BufferedImage img2)
      Return the difference in percent between two buffered images.
      static int pixelDiff​(int rgb1, int rgb2)
      Compare two pixels
      static java.awt.image.BufferedImage readImageFromResources​(java.lang.String path)
      Read image from the provided path.
      static java.awt.image.BufferedImage resize​(java.awt.image.BufferedImage img, int newW, int newH)
      Resize image to new dimensions and return new image.
      static void saveImage​(java.io.File pathFile, java.awt.image.BufferedImage image)
      Save image to the provided path.
      static java.awt.image.BufferedImage toBufferedImage​(java.awt.Image img)
      Convert image to buffered image.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ImageComparisonUtil

        public ImageComparisonUtil()
    • Method Detail

      • readImageFromResources

        public static java.awt.image.BufferedImage readImageFromResources​(java.lang.String path)
                                                                   throws ImageComparisonException
        Read image from the provided path.
        Parameters:
        path - the path where contains image.
        Returns:
        the BufferedImage object of this specific image.
        Throws:
        ImageComparisonException - due to read the image from resources.
      • saveImage

        public static void saveImage​(java.io.File pathFile,
                                     java.awt.image.BufferedImage image)
                              throws ImageComparisonException
        Save image to the provided path.
        Parameters:
        pathFile - the path to the saving image.
        image - the BufferedImage object of this specific image.
        Throws:
        ImageComparisonException - due to save image.
      • resize

        public static java.awt.image.BufferedImage resize​(java.awt.image.BufferedImage img,
                                                          int newW,
                                                          int newH)
        Resize image to new dimensions and return new image.
        Parameters:
        img - the object of the image to be resized.
        newW - the new width.
        newH - the new height.
        Returns:
        resized BufferedImage object.
      • toBufferedImage

        public static java.awt.image.BufferedImage toBufferedImage​(java.awt.Image img)
        Convert image to buffered image.
        Parameters:
        img - the object of the image to be converted to buffered image.
        Returns:
        the converted buffered image.
      • getDifferencePercent

        public static float getDifferencePercent​(java.awt.image.BufferedImage img1,
                                                 java.awt.image.BufferedImage img2)
        Return the difference in percent between two buffered images.
        Parameters:
        img1 - the first image.
        img2 - the second image.
        Returns:
        difference percent.
      • pixelDiff

        public static int pixelDiff​(int rgb1,
                                    int rgb2)
        Compare two pixels
        Parameters:
        rgb1 - the first rgb
        rgb2 - the second rgn
        Returns:
        the difference.