Class ImageUtil


  • public class ImageUtil
    extends Object
    Author:
    Kilian
    • Constructor Detail

      • ImageUtil

        public ImageUtil()
    • Method Detail

      • getScaledInstance

        public static BufferedImage getScaledInstance​(BufferedImage source,
                                                      int width,
                                                      int height)
        Resize the buffered image to an arbitrary dimension

        If a high quality interpolated thumbnail is required createThumbnail(BufferedImage, int, int) may be more suited.

        Parameters:
        source - the source image
        width - the new width
        height - the new height
        Returns:
        the resized image
        Since:
        1.0.0 com.github.kilianB, 1.4.2 fixed not using awt rescale com.github.kilianB, 1.5.3 fixed using ImageTypeSpecifier to create compatible images for custom type com.github.kilianB
      • createThumbnail

        public static BufferedImage createThumbnail​(BufferedImage image,
                                                    int newWidth,
                                                    int newHeight)

        Returns a thumbnail of a source image.

        TODO LGPL LICENSE!!
        Parameters:
        image - the source image
        newWidth - the width of the thumbnail
        newHeight - the height of the thumbnail
        Returns:
        a new compatible BufferedImage containing a thumbnail of image
        Throws:
        IllegalArgumentException - if newWidth is larger than the width of image or if newHeight is larger than the height of image or if one the dimensions is not > 0 @ since 1.5.0
      • toNewType

        public static BufferedImage toNewType​(BufferedImage original,
                                              int newType)
        Convert the image to an image of the new type
        Parameters:
        original - the original image to convert
        newType - the new type
        Returns:
        a copy of the original image with new pixel type
      • toNewType

        public static BufferedImage toNewType​(BufferedImage original,
                                              ImageUtil.BImageType newType)
        Convert the image to an image of the new type
        Parameters:
        original - the original image to convert
        newType - the new type
        Returns:
        a copy of the original image with new pixel type
      • interpolateColor

        public static javafx.scene.paint.Color interpolateColor​(javafx.scene.image.Image image)
        Calculate the interpolated average color of the image
        Parameters:
        image - the source image
        Returns:
        the average color of the image
        Since:
        1.0.0 com.github.kilianB
      • interpolateColor

        public static javafx.scene.paint.Color interpolateColor​(BufferedImage bImage)
        Calculate the interpolated average color of the image
        Parameters:
        bImage - the source image
        Returns:
        the average color of the image
        Since:
        2.0.1
      • dominantColor

        public static javafx.scene.paint.Color dominantColor​(BufferedImage bImage)
        Return the dominant color of this image. The dominant color is the color that most often occurred in this image. Be aware that calculating the average color using this approach is a rather expensive operation.

        Parameters:
        bImage - The source image
        Returns:
        the dominant color of this image
        Since:
        2.0.1
      • dominantColor

        public static javafx.scene.paint.Color dominantColor​(javafx.scene.image.Image image)
        Return the dominant color of this image. The dominant color is the color that most often occurred in this image. Be aware that calculating the average color using this approach is a rather expensive operation.

        Parameters:
        image - The source image
        Returns:
        the dominant color of this image
        Since:
        1.0.0 com.github.kilianB
      • meanColor

        public static javafx.scene.paint.Color meanColor​(BufferedImage image)
        Calculate the average color of this image. The average color is determined by summing the squared argb component of each pixel and determining the mean value of these.
        Parameters:
        image - The source image
        Returns:
        The average mean color of this image
        Since:
        2.0.1
      • meanColor

        public static javafx.scene.paint.Color meanColor​(javafx.scene.image.Image image)
        Calculate the average color of this image. The average color is determined by summing the squared argb component of each pixel and determining the mean value of these.
        Parameters:
        image - The source image
        Returns:
        The average mean color of this image
        Since:
        1.0.0 com.github.kilianB