belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1
ColorUtils
  public
  
  final
  
  class
  ColorUtils
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.support.v4.graphics.ColorUtils | 
A set of color-related utility methods, building upon those available in Color.
Summary
| Public methods | |
|---|---|
| 
        
        
        static
        
        
        int | 
      HSLToColor(float[] hsl)
      Convert HSL (hue-saturation-lightness) components to a RGB color. | 
| 
        
        
        static
        
        
        int | 
      LABToColor(double l, double a, double b)
      Converts a color from CIE Lab to its RGB representation. | 
| 
        
        
        static
        
        
        void | 
      LABToXYZ(double l, double a, double b, double[] outXyz)
      Converts a color from CIE Lab to CIE XYZ representation. | 
| 
        
        
        static
        
        
        void | 
      RGBToHSL(int r, int g, int b, float[] outHsl)
      Convert RGB components to HSL (hue-saturation-lightness). | 
| 
        
        
        static
        
        
        void | 
      RGBToLAB(int r, int g, int b, double[] outLab)
      Convert RGB components to its CIE Lab representative components. | 
| 
        
        
        static
        
        
        void | 
      RGBToXYZ(int r, int g, int b, double[] outXyz)
      Convert RGB components to its CIE XYZ representative components. | 
| 
        
        
        static
        
        
        int | 
      XYZToColor(double x, double y, double z)
      Converts a color from CIE XYZ to its RGB representation. | 
| 
        
        
        static
        
        
        void | 
      XYZToLAB(double x, double y, double z, double[] outLab)
      Converts a color from CIE XYZ to CIE Lab representation. | 
| 
        
        
        static
        
        
        int | 
      blendARGB(int color1, int color2, float ratio)
      Blend between two ARGB colors using the given ratio. | 
| 
        
        
        static
        
        
        void | 
      blendHSL(float[] hsl1, float[] hsl2, float ratio, float[] outResult)
      Blend between  | 
| 
        
        
        static
        
        
        void | 
      blendLAB(double[] lab1, double[] lab2, double ratio, double[] outResult)
      Blend between two CIE-LAB colors using the given ratio. | 
| 
        
        
        static
        
        
        double | 
      calculateContrast(int foreground, int background)
      Returns the contrast ratio between  | 
| 
        
        
        static
        
        
        double | 
      calculateLuminance(int color)
      Returns the luminance of a color as a float between  | 
| 
        
        
        static
        
        
        int | 
      calculateMinimumAlpha(int foreground, int background, float minContrastRatio)
      Calculates the minimum alpha value which can be applied to  | 
| 
        
        
        static
        
        
        void | 
      colorToHSL(int color, float[] outHsl)
      Convert the ARGB color to its HSL (hue-saturation-lightness) components. | 
| 
        
        
        static
        
        
        void | 
      colorToLAB(int color, double[] outLab)
      Convert the ARGB color to its CIE Lab representative components. | 
| 
        
        
        static
        
        
        void | 
      colorToXYZ(int color, double[] outXyz)
      Convert the ARGB color to its CIE XYZ representative components. | 
| 
        
        
        static
        
        
        int | 
      compositeColors(int foreground, int background)
      Composite two potentially translucent colors over each other and returns the result. | 
| 
        
        
        static
        
        
        double | 
      distanceEuclidean(double[] labX, double[] labY)
      Returns the euclidean distance between two LAB colors. | 
| 
        
        
        static
        
        
        int | 
      setAlphaComponent(int color, int alpha)
      Set the alpha component of  | 
| Inherited methods | |
|---|---|
|  From
class 
  
    java.lang.Object
  
 | |
Public methods
HSLToColor
int HSLToColor (float[] hsl)
Convert HSL (hue-saturation-lightness) components to a RGB color.
- hsl[0] is Hue [0 .. 360)
- hsl[1] is Saturation [0...1]
- hsl[2] is Lightness [0...1]
| Parameters | |
|---|---|
| hsl | float: 3-element array which holds the input HSL components | 
| Returns | |
|---|---|
| int | the resulting RGB color | 
LABToColor
int LABToColor (double l, 
                double a, 
                double b)Converts a color from CIE Lab to its RGB representation.
| Parameters | |
|---|---|
| l | double: L component value [0...100]Value is between 0.0 and 100.0 inclusive. | 
| a | double: A component value [-128...127]Value is between -128.0 and 127.0 inclusive. | 
| b | double: B component value [-128...127]Value is between -128.0 and 127.0 inclusive. | 
| Returns | |
|---|---|
| int | int containing the RGB representation | 
LABToXYZ
void LABToXYZ (double l, 
                double a, 
                double b, 
                double[] outXyz)Converts a color from CIE Lab to CIE XYZ representation.
The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).
- outXyz[0] is X [0 ...95.047)
- outXyz[1] is Y [0...100)
- outXyz[2] is Z [0...108.883)
| Parameters | |
|---|---|
| l | double: L component value [0...100)Value is between 0.0 and 100.0 inclusive. | 
| a | double: A component value [-128...127)Value is between -128.0 and 127.0 inclusive. | 
| b | double: B component value [-128...127)Value is between -128.0 and 127.0 inclusive. | 
| outXyz | double: 3-element array which holds the resulting XYZ components | 
RGBToHSL
void RGBToHSL (int r, 
                int g, 
                int b, 
                float[] outHsl)Convert RGB components to HSL (hue-saturation-lightness).
- outHsl[0] is Hue [0 .. 360)
- outHsl[1] is Saturation [0...1]
- outHsl[2] is Lightness [0...1]
| Parameters | |
|---|---|
| r | int: red component value [0..255]Value is 255 or less. | 
| g | int: green component value [0..255]Value is 255 or less. | 
| b | int: blue component value [0..255]Value is 255 or less. | 
| outHsl | float: 3-element array which holds the resulting HSL components | 
RGBToLAB
void RGBToLAB (int r, 
                int g, 
                int b, 
                double[] outLab)Convert RGB components to its CIE Lab representative components.
- outLab[0] is L [0 ...1)
- outLab[1] is a [-128...127)
- outLab[2] is b [-128...127)
| Parameters | |
|---|---|
| r | int: red component value [0..255]Value is 255 or less. | 
| g | int: green component value [0..255]Value is 255 or less. | 
| b | int: blue component value [0..255]Value is 255 or less. | 
| outLab | double: 3-element array which holds the resulting LAB components | 
RGBToXYZ
void RGBToXYZ (int r, 
                int g, 
                int b, 
                double[] outXyz)Convert RGB components to its CIE XYZ representative components.
The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).
- outXyz[0] is X [0 ...95.047)
- outXyz[1] is Y [0...100)
- outXyz[2] is Z [0...108.883)
| Parameters | |
|---|---|
| r | int: red component value [0..255]Value is 255 or less. | 
| g | int: green component value [0..255]Value is 255 or less. | 
| b | int: blue component value [0..255]Value is 255 or less. | 
| outXyz | double: 3-element array which holds the resulting XYZ components | 
XYZToColor
int XYZToColor (double x, 
                double y, 
                double z)Converts a color from CIE XYZ to its RGB representation.
This method expects the XYZ representation to use the D65 illuminant and the CIE 2° Standard Observer (1931).
| Parameters | |
|---|---|
| x | double: X component value [0...95.047)Value is between 0.0 and 95.047 inclusive. | 
| y | double: Y component value [0...100)Value is between 0.0 and 100.0 inclusive. | 
| z | double: Z component value [0...108.883)Value is between 0.0 and 108.883 inclusive. | 
| Returns | |
|---|---|
| int | int containing the RGB representation | 
XYZToLAB
void XYZToLAB (double x, 
                double y, 
                double z, 
                double[] outLab)Converts a color from CIE XYZ to CIE Lab representation.
This method expects the XYZ representation to use the D65 illuminant and the CIE 2° Standard Observer (1931).
- outLab[0] is L [0 ...1)
- outLab[1] is a [-128...127)
- outLab[2] is b [-128...127)
| Parameters | |
|---|---|
| x | double: X component value [0...95.047)Value is between 0.0 and 95.047 inclusive. | 
| y | double: Y component value [0...100)Value is between 0.0 and 100.0 inclusive. | 
| z | double: Z component value [0...108.883)Value is between 0.0 and 108.883 inclusive. | 
| outLab | double: 3-element array which holds the resulting Lab components | 
blendARGB
int blendARGB (int color1, 
                int color2, 
                float ratio)Blend between two ARGB colors using the given ratio.
A blend ratio of 0.0 will result in color1, 0.5 will give an even blend,
 1.0 will result in color2.
| Parameters | |
|---|---|
| color1 | int: the first ARGB color | 
| color2 | int: the second ARGB color | 
| ratio | float: the blend ratio ofcolor1tocolor2Value is between 0.0 and 1.0 inclusive. | 
| Returns | |
|---|---|
| int | |
blendHSL
void blendHSL (float[] hsl1, 
                float[] hsl2, 
                float ratio, 
                float[] outResult)Blend between hsl1 and hsl2 using the given ratio. This will interpolate
 the hue using the shortest angle.
 
A blend ratio of 0.0 will result in hsl1, 0.5 will give an even blend,
 1.0 will result in hsl2.
| Parameters | |
|---|---|
| hsl1 | float: 3-element array which holds the first HSL color | 
| hsl2 | float: 3-element array which holds the second HSL color | 
| ratio | float: the blend ratio ofhsl1tohsl2Value is between 0.0 and 1.0 inclusive. | 
| outResult | float: 3-element array which holds the resulting HSL components | 
blendLAB
void blendLAB (double[] lab1, 
                double[] lab2, 
                double ratio, 
                double[] outResult)Blend between two CIE-LAB colors using the given ratio.
A blend ratio of 0.0 will result in lab1, 0.5 will give an even blend,
 1.0 will result in lab2.
| Parameters | |
|---|---|
| lab1 | double: 3-element array which holds the first LAB color | 
| lab2 | double: 3-element array which holds the second LAB color | 
| ratio | double: the blend ratio oflab1tolab2Value is between 0.0 and 1.0 inclusive. | 
| outResult | double: 3-element array which holds the resulting LAB components | 
calculateContrast
double calculateContrast (int foreground, 
                int background)Returns the contrast ratio between foreground and background.
 background must be opaque.
 
Formula defined here.
| Parameters | |
|---|---|
| foreground | int | 
| background | int | 
| Returns | |
|---|---|
| double | |
calculateLuminance
double calculateLuminance (int color)
Returns the luminance of a color as a float between 0.0 and 1.0.
 
Defined as the Y component in the XYZ representation of color.
| Parameters | |
|---|---|
| color | int | 
| Returns | |
|---|---|
| double | Value is between 0.0 and 1.0 inclusive. | 
calculateMinimumAlpha
int calculateMinimumAlpha (int foreground, 
                int background, 
                float minContrastRatio)Calculates the minimum alpha value which can be applied to foreground so that would
 have a contrast value of at least minContrastRatio when compared to
 background.
| Parameters | |
|---|---|
| foreground | int: the foreground color | 
| background | int: the opaque background color | 
| minContrastRatio | float: the minimum contrast ratio | 
| Returns | |
|---|---|
| int | the alpha value in the range 0-255, or -1 if no value could be calculated | 
colorToHSL
void colorToHSL (int color, 
                float[] outHsl)Convert the ARGB color to its HSL (hue-saturation-lightness) components.
- outHsl[0] is Hue [0 .. 360)
- outHsl[1] is Saturation [0...1]
- outHsl[2] is Lightness [0...1]
| Parameters | |
|---|---|
| color | int: the ARGB color to convert. The alpha component is ignored | 
| outHsl | float: 3-element array which holds the resulting HSL components | 
colorToLAB
void colorToLAB (int color, 
                double[] outLab)Convert the ARGB color to its CIE Lab representative components.
| Parameters | |
|---|---|
| color | int: the ARGB color to convert. The alpha component is ignored | 
| outLab | double: 3-element array which holds the resulting LAB components | 
colorToXYZ
void colorToXYZ (int color, 
                double[] outXyz)Convert the ARGB color to its CIE XYZ representative components.
The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).
- outXyz[0] is X [0 ...95.047)
- outXyz[1] is Y [0...100)
- outXyz[2] is Z [0...108.883)
| Parameters | |
|---|---|
| color | int: the ARGB color to convert. The alpha component is ignored | 
| outXyz | double: 3-element array which holds the resulting LAB components | 
compositeColors
int compositeColors (int foreground, 
                int background)Composite two potentially translucent colors over each other and returns the result.
| Parameters | |
|---|---|
| foreground | int | 
| background | int | 
| Returns | |
|---|---|
| int | |
distanceEuclidean
double distanceEuclidean (double[] labX, 
                double[] labY)Returns the euclidean distance between two LAB colors.
| Parameters | |
|---|---|
| labX | double | 
| labY | double | 
| Returns | |
|---|---|
| double | |
setAlphaComponent
int setAlphaComponent (int color, 
                int alpha)Set the alpha component of color to be alpha.
| Parameters | |
|---|---|
| color | int | 
| alpha | intValue is 255 or less. | 
| Returns | |
|---|---|
| int | |
- Classes
