Class ColorUtils


  • public class ColorUtils
    extends java.lang.Object
    Several useful methods for Color.
    • Constructor Summary

      Constructors 
      Constructor Description
      ColorUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float[] applyDifference​(float[] from, int[] diff)  
      static int[] calculateDifferent​(float[] from, float[] to)  
      static java.awt.Color getDerivedColor​(java.awt.Color color, float ratio)
      Gets a derived color from an existing color.
      static int HSLtoRGB​(float[] hsl)
      Converts from HSL color space to RGB color.
      static float[] RGBtoHSL​(java.awt.Color colorRGB)
      Converts a color from RBG to HSL color space.
      static java.awt.Color[] toColors​(boolean hasAlpha, int... colors)
      Simply calls new Color(color, hasalpha) for each color in colors and returns all of them.
      static java.awt.Color toGrayscale​(java.awt.Color c)
      Converts from a color to gray scale color.
      • Methods inherited from class java.lang.Object

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

      • ColorUtils

        public ColorUtils()
    • Method Detail

      • getDerivedColor

        public static java.awt.Color getDerivedColor​(java.awt.Color color,
                                                     float ratio)
        Gets a derived color from an existing color. The derived color is either lighter or darker version of the given color with the same hue.
        Parameters:
        color - the given color.
        ratio - the ratio. 0.5f if the same color. Any ratio greater than 0.5f will make the result color lighter. Smaller than 0.5f will make the color darker.
        Returns:
        the derived color.
      • RGBtoHSL

        public static float[] RGBtoHSL​(java.awt.Color colorRGB)
        Converts a color from RBG to HSL color space.
        Parameters:
        colorRGB - the Color.
        Returns:
        color space in HSL.
      • HSLtoRGB

        public static int HSLtoRGB​(float[] hsl)
        Converts from HSL color space to RGB color.
        Parameters:
        hsl - the hsl values.
        Returns:
        the RGB color.
      • calculateDifferent

        public static int[] calculateDifferent​(float[] from,
                                               float[] to)
      • applyDifference

        public static float[] applyDifference​(float[] from,
                                              int[] diff)
      • toColors

        public static java.awt.Color[] toColors​(boolean hasAlpha,
                                                int... colors)
        Simply calls new Color(color, hasalpha) for each color in colors and returns all of them.
        Parameters:
        hasAlpha - true to consider the alpha when creating the Color.
        colors - the color value.
        Returns:
        the colors with alpha added.
      • toGrayscale

        public static java.awt.Color toGrayscale​(java.awt.Color c)
        Converts from a color to gray scale color.
        Parameters:
        c - a color.
        Returns:
        a color in gray scale.