Most visited

Recently visited

ColorUtils

public final class ColorUtils
extends Object

java.lang.Object
   ↳ android.support.v4.graphics.ColorUtils


一套与颜色相关的实用方法,建立在 Color可用方法的 Color 。

Summary

Public methods

static int HSLToColor(float[] hsl)

将HSL(色相饱和度 - 亮度)分量转换为RGB颜色。

static int LABToColor(double l, double a, double b)

将CIE Lab中的颜色转换为RGB表示。

static void LABToXYZ(double l, double a, double b, double[] outXyz)

将颜色从CIE Lab转换为CIE XYZ表示。

static void RGBToHSL(int r, int g, int b, float[] outHsl)

将RGB分量转换为HSL(色相饱和度 - 亮度)。

static void RGBToLAB(int r, int g, int b, double[] outLab)

将RGB组件转换为其CIE Lab代表组件。

static void RGBToXYZ(int r, int g, int b, double[] outXyz)

将RGB组件转换为它的CIE XYZ代表组件。

static int XYZToColor(double x, double y, double z)

将颜色从CIE XYZ转换为其RGB表示。

static void XYZToLAB(double x, double y, double z, double[] outLab)

将颜色从CIE XYZ转换为CIE Lab表示。

static int blendARGB(int color1, int color2, float ratio)

按照给定的比例混合两种ARGB颜色。

static void blendHSL(float[] hsl1, float[] hsl2, float ratio, float[] outResult)

使用给定的比率在 hsl1和 hsl2之间混合。

static void blendLAB(double[] lab1, double[] lab2, double ratio, double[] outResult)

使用给定比例混合两种CIE-LAB颜色。

static double calculateContrast(int foreground, int background)

返回 foreground和 background之间的对比度。

static double calculateLuminance(int color)

以 0.0和 1.0之间的浮点数形式返回颜色的亮度。

static int calculateMinimumAlpha(int foreground, int background, float minContrastRatio)

计算可应用于 foreground的最小alpha值,以便与 minContrastRatio相比,对比度值至少为 background 。

static void colorToHSL(int color, float[] outHsl)

将ARGB颜色转换为其HSL(色相饱和度 - 亮度)分量。

static void colorToLAB(int color, double[] outLab)

将ARGB颜色转换为其CIE Lab代表性组件。

static void colorToXYZ(int color, double[] outXyz)

将ARGB颜色转换为其CIE XYZ代表性组件。

static int compositeColors(int foreground, int background)

将两种可能半透明的颜色相互复合并返回结果。

static double distanceEuclidean(double[] labX, double[] labY)

返回两个LAB颜色之间的欧氏距离。

static int setAlphaComponent(int color, int alpha)

将 color的alpha分量设置为 alpha 。

Inherited methods

From class java.lang.Object

Public methods

HSLToColor

int HSLToColor (float[] hsl)

将HSL(色相饱和度 - 亮度)分量转换为RGB颜色。

  • hsl[0] is Hue [0 .. 360)
  • hsl[1] is Saturation [0...1]
  • hsl[2] is Lightness [0...1]
If hsv values are out of range, they are pinned.

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)

将CIE Lab中的颜色转换为RGB表示。

Parameters
l double: L component value [0...100]
a double: A component value [-128...127]
b double: B component value [-128...127]
Returns
int int containing the RGB representation

LABToXYZ

void LABToXYZ (double l, 
                double a, 
                double b, 
                double[] outXyz)

将颜色从CIE Lab转换为CIE XYZ表示。

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)
a double: A component value [-128...127)
b double: B component value [-128...127)
outXyz double: 3-element array which holds the resulting XYZ components

RGBToHSL

void RGBToHSL (int r, 
                int g, 
                int b, 
                float[] outHsl)

将RGB分量转换为HSL(色相饱和度 - 亮度)。

  • 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]
g int: green component value [0..255]
b int: blue component value [0..255]
outHsl float: 3-element array which holds the resulting HSL components

RGBToLAB

void RGBToLAB (int r, 
                int g, 
                int b, 
                double[] outLab)

将RGB组件转换为其CIE Lab代表组件。

  • 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]
g int: green component value [0..255]
b int: blue component value [0..255]
outLab double: 3-element array which holds the resulting LAB components

RGBToXYZ

void RGBToXYZ (int r, 
                int g, 
                int b, 
                double[] outXyz)

将RGB组件转换为它的CIE XYZ代表组件。

由此产生的XYZ表示将使用D65光源和CIE 2°标准观测器(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]
g int: green component value [0..255]
b int: blue component value [0..255]
outXyz double: 3-element array which holds the resulting XYZ components

XYZToColor

int XYZToColor (double x, 
                double y, 
                double z)

将颜色从CIE XYZ转换为其RGB表示。

此方法预计XYZ表示使用D65光源和CIE 2°标准观察者(1931年)。

Parameters
x double: X component value [0...95.047)
y double: Y component value [0...100)
z double: Z component value [0...108.883)
Returns
int int containing the RGB representation

XYZToLAB

void XYZToLAB (double x, 
                double y, 
                double z, 
                double[] outLab)

将颜色从CIE XYZ转换为CIE Lab表示。

此方法预计XYZ表示使用D65光源和CIE 2°标准观察者(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)
y double: Y component value [0...100)
z double: Z component value [0...108.883)
outLab double: 3-element array which holds the resulting Lab components

blendARGB

int blendARGB (int color1, 
                int color2, 
                float ratio)

按照给定的比例混合两种ARGB颜色。

0.0的混合比率将导致 color1将会得到均匀的混合,1.0将导致 color2 。

Parameters
color1 int: the first ARGB color
color2 int: the second ARGB color
ratio float: the blend ratio of color1 to color2
Returns
int

blendHSL

void blendHSL (float[] hsl1, 
                float[] hsl2, 
                float ratio, 
                float[] outResult)

使用给定的比率在hsl1和hsl2之间混合。 这将使用最短角度插补色相。

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 of hsl1 to hsl2
outResult float: 3-element array which holds the resulting HSL components

blendLAB

void blendLAB (double[] lab1, 
                double[] lab2, 
                double ratio, 
                double[] outResult)

使用给定比例混合两种CIE-LAB颜色。

0.0的混合比率将导致 lab1将导致均匀混合,1.0导致 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 of lab1 to lab2
outResult double: 3-element array which holds the resulting LAB components

calculateContrast

double calculateContrast (int foreground, 
                int background)

返回foreground和background之间的对比度。 background必须是不透明的。

公式定义为 here 。

Parameters
foreground int
background int
Returns
double

calculateLuminance

double calculateLuminance (int color)

以 0.0和 1.0之间的浮点数形式返回颜色的亮度。

定义为XYZ表示 color的Y分量。

Parameters
color int
Returns
double

calculateMinimumAlpha

int calculateMinimumAlpha (int foreground, 
                int background, 
                float minContrastRatio)

计算可应用于 foreground的最小阿尔法值,以便与 minContrastRatio比较时对比度值至少为 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)

将ARGB颜色转换为其HSL(色相饱和度 - 亮度)分量。

  • 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)

将ARGB颜色转换为其CIE Lab代表性组件。

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)

将ARGB颜色转换为其CIE XYZ代表性组件。

由此产生的XYZ表示将使用D65光源和CIE 2°标准观测器(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)

将两种可能半透明的颜色相互复合并返回结果。

Parameters
foreground int
background int
Returns
int

distanceEuclidean

double distanceEuclidean (double[] labX, 
                double[] labY)

返回两个LAB颜色之间的欧氏距离。

Parameters
labX double
labY double
Returns
double

setAlphaComponent

int setAlphaComponent (int color, 
                int alpha)

将 color的alpha分量设置为 alpha 。

Parameters
color int
alpha int
Returns
int

Hooray!