Class ColorThief


  • public class ColorThief
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ColorThief()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] getColor​(java.awt.image.BufferedImage sourceImage)
      Use the median cut algorithm to cluster similar colors and return the base color from the largest cluster.
      static int[] getColor​(java.awt.image.BufferedImage sourceImage, int quality, boolean ignoreWhite)
      Use the median cut algorithm to cluster similar colors and return the base color from the largest cluster.
      static MMCQ.CMap getColorMap​(java.awt.image.BufferedImage sourceImage, int colorCount)
      Use the median cut algorithm to cluster similar colors.
      static MMCQ.CMap getColorMap​(java.awt.image.BufferedImage sourceImage, int colorCount, int quality, boolean ignoreWhite)
      Use the median cut algorithm to cluster similar colors.
      static int[][] getPalette​(java.awt.image.BufferedImage sourceImage, int colorCount)
      Use the median cut algorithm to cluster similar colors.
      static int[][] getPalette​(java.awt.image.BufferedImage sourceImage, int colorCount, int quality, boolean ignoreWhite)
      Use the median cut algorithm to cluster similar colors.
      • Methods inherited from class java.lang.Object

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

      • ColorThief

        public ColorThief()
    • Method Detail

      • getColor

        public static int[] getColor​(java.awt.image.BufferedImage sourceImage)
        Use the median cut algorithm to cluster similar colors and return the base color from the largest cluster.
        Parameters:
        sourceImage - the source image
        Returns:
        the dominant color as RGB array
      • getColor

        public static int[] getColor​(java.awt.image.BufferedImage sourceImage,
                                     int quality,
                                     boolean ignoreWhite)
        Use the median cut algorithm to cluster similar colors and return the base color from the largest cluster.
        Parameters:
        sourceImage - the source image
        quality - 1 is the highest quality settings. 10 is the default. There is a trade-off between quality and speed. The bigger the number, the faster a color will be returned but the greater the likelihood that it will not be the visually most dominant color.
        ignoreWhite - if true, white pixels are ignored
        Returns:
        the dominant color as RGB array
        Throws:
        java.lang.IllegalArgumentException - if quality is < 1
      • getPalette

        public static int[][] getPalette​(java.awt.image.BufferedImage sourceImage,
                                         int colorCount)
        Use the median cut algorithm to cluster similar colors.
        Parameters:
        sourceImage - the source image
        colorCount - the size of the palette; the number of colors returned
        Returns:
        the palette as array of RGB arrays
      • getPalette

        public static int[][] getPalette​(java.awt.image.BufferedImage sourceImage,
                                         int colorCount,
                                         int quality,
                                         boolean ignoreWhite)
        Use the median cut algorithm to cluster similar colors.
        Parameters:
        sourceImage - the source image
        colorCount - the size of the palette; the number of colors returned
        quality - 1 is the highest quality settings. 10 is the default. There is a trade-off between quality and speed. The bigger the number, the faster the palette generation but the greater the likelihood that colors will be missed.
        ignoreWhite - if true, white pixels are ignored
        Returns:
        the palette as array of RGB arrays
        Throws:
        java.lang.IllegalArgumentException - if quality is < 1
      • getColorMap

        public static MMCQ.CMap getColorMap​(java.awt.image.BufferedImage sourceImage,
                                            int colorCount)
        Use the median cut algorithm to cluster similar colors.
        Parameters:
        sourceImage - the source image
        colorCount - the size of the palette; the number of colors returned (minimum 2, maximum 256)
        Returns:
        the color map
      • getColorMap

        public static MMCQ.CMap getColorMap​(java.awt.image.BufferedImage sourceImage,
                                            int colorCount,
                                            int quality,
                                            boolean ignoreWhite)
        Use the median cut algorithm to cluster similar colors.
        Parameters:
        sourceImage - the source image
        colorCount - the size of the palette; the number of colors returned (minimum 2, maximum 256)
        quality - 1 is the highest quality settings. 10 is the default. There is a trade-off between quality and speed. The bigger the number, the faster the palette generation but the greater the likelihood that colors will be missed.
        ignoreWhite - if true, white pixels are ignored
        Returns:
        the color map
        Throws:
        java.lang.IllegalArgumentException - if quality is < 1