Google 致力于为黑人社区推动种族平等。查看具体举措

ColorUtils

class ColorUtils
kotlin.Any
   ↳ androidx.core.graphics.ColorUtils

A set of color-related utility methods, building upon those available in Color.

Summary

Public methods
static Int
HSLToColor(@NonNull hsl: FloatArray)

Convert HSL (hue-saturation-lightness) components to a RGB color.

static Int
LABToColor(@FloatRange(0.0, 100) l: Double, @FloatRange(-128, 127) a: Double, @FloatRange(-128, 127) b: Double)

Converts a color from CIE Lab to its RGB representation.

static Unit
LABToXYZ(@FloatRange(0.0, 100) l: Double, @FloatRange(-128, 127) a: Double, @FloatRange(-128, 127) b: Double, @NonNull outXyz: DoubleArray)

Converts a color from CIE Lab to CIE XYZ representation.

static Unit
RGBToHSL(@IntRange(0, 255) r: Int, @IntRange(0, 255) g: Int, @IntRange(0, 255) b: Int, @NonNull outHsl: FloatArray)

Convert RGB components to HSL (hue-saturation-lightness).

static Unit
RGBToLAB(@IntRange(0, 255) r: Int, @IntRange(0, 255) g: Int, @IntRange(0, 255) b: Int, @NonNull outLab: DoubleArray)

Convert RGB components to its CIE Lab representative components.

static Unit
RGBToXYZ(@IntRange(0, 255) r: Int, @IntRange(0, 255) g: Int, @IntRange(0, 255) b: Int, @NonNull outXyz: DoubleArray)

Convert RGB components to its CIE XYZ representative components.

static Int
XYZToColor(@FloatRange(0.0, 95.047) x: Double, @FloatRange(0.0, 100.0) y: Double, @FloatRange(0.0, 108.883) z: Double)

Converts a color from CIE XYZ to its RGB representation.

static Unit
XYZToLAB(@FloatRange(0.0, 95.047) x: Double, @FloatRange(0.0, 100.0) y: Double, @FloatRange(0.0, 108.883) z: Double, @NonNull outLab: DoubleArray)

Converts a color from CIE XYZ to CIE Lab representation.

static Int
blendARGB(@ColorInt color1: Int, @ColorInt color2: Int, @FloatRange(0.0, 1.0) ratio: Float)

Blend between two ARGB colors using the given ratio.

static Unit
blendHSL(@NonNull hsl1: FloatArray, @NonNull hsl2: FloatArray, @FloatRange(0.0, 1.0) ratio: Float, @NonNull outResult: FloatArray)

Blend between hsl1 and hsl2 using the given ratio.

static Unit
blendLAB(@NonNull lab1: DoubleArray, @NonNull lab2: DoubleArray, @FloatRange(0.0, 1.0) ratio: Double, @NonNull outResult: DoubleArray)

Blend between two CIE-LAB colors using the given ratio.

static Double
calculateContrast(@ColorInt foreground