public class Colors extends Object
Modifier and Type | Method and Description |
---|---|
static Color |
alpha(Color c,
float alpha)
Create a new color identical to the given one, but having its alpha value replaced with the
given one.
|
static Color |
alpha(Color c,
int alpha)
Create a new color identical to the given one, but having its alpha value replaced with the
given one.
|
static Color |
alphaComposite(Color fg,
Color bg)
Composite two colors using alpha compositing.
|
static Color |
fromHSB(float[] hsl)
Convert the given color in the HSB (sometimes called HSL) color model into a
Color in
the color space sRGB. |
static Color |
fromHSB(float h,
float s,
float b)
Convert the given color in the HSB (sometimes called HSL) color model into a
Color in
the color space sRGB. |
static Color |
invert(Color c)
Create a new color which is the inverse of the given one.
|
static float |
luminance(Color c)
Return the color's luminance normalized to the range [0,1].
|
static float |
luminanceContrast(Color c1,
Color c2)
Return luminance contrast between the two colors normalized to the range [0,1].
|
static Color |
optimizeContrastColor(Color color,
Color background,
int minimumContrastPercent) |
static Color |
optimizeContrastColorNoAlpha(Color color,
Color background,
int minimumContrastPercent)
This is an experimental new contrast optimization strategy.
|
static Color |
optimizeForegroundContrast(Color fg,
Color bg)
Optimize the contrast of the foreground color against the background by inverting it, if
inversion leads to a higher contrast.
|
static Color |
parseColor(String colorString) |
static float[] |
toHSL(Color c)
Convert the given color to the HSB (sometimes called HSL) color model.
|
static String |
toHtml(Color c)
Convert the given RGB(A) color into an HTML color code of the Form
#[6 or 8 hex digits] . |
public static Color alpha(Color c, int alpha)
c
- alpha
- public static Color alpha(Color c, float alpha)
c
- alpha
- public static Color alphaComposite(Color fg, Color bg)
fg
- the foreground colorbg
- the background colorpublic static float luminance(Color c)
c
- public static float luminanceContrast(Color c1, Color c2)
c1
- first colorc2
- second colorpublic static Color invert(Color c)
c
- public static Color optimizeForegroundContrast(Color fg, Color bg)
fg
- the foreground colorbg
- the background colorpublic static Color optimizeContrastColorNoAlpha(Color color, Color background, int minimumContrastPercent)
color
- background
- minimumContrastPercent
- public static Color optimizeContrastColor(Color color, Color background, int minimumContrastPercent)
public static float[] toHSL(Color c)
c
- public static Color fromHSB(float[] hsl)
Color
in
the color space sRGB. The given values must be normalized to the range [0,1].hsl
- the HSL componentspublic static Color fromHSB(float h, float s, float b)
Color
in
the color space sRGB. The given values must be normalized to the range [0,1].h
- hues
- saturationb
- brightnesspublic static String toHtml(Color c)
#[6 or 8 hex digits]
. The conversion will automatically include the alpha channel
(8 hex digits) or not (6 digits) depending on whether the color has transparency (
Color.getTransparency()
).c
- the colorCopyright © 2024 levigo holding gmbh. All rights reserved.