public
class
Color
extends Object
java.lang.Object | |
↳ | android.graphics.Color |
The Color class defines methods for creating and converting color ints. Colors are represented as packed ints, made up of 4 bytes: alpha, red, green, blue. The values are unpremultiplied, meaning any transparency is stored solely in the alpha component, and not in the color components. The components are stored as follows (alpha << 24) | (red << 16) | (green << 8) | blue. Each component ranges between 0..255 with 0 meaning no contribution for that component, and 255 meaning 100% contribution. Thus opaque-black would be 0xFF000000 (100% opaque but no contributions from red, green, or blue), and opaque-white would be 0xFFFFFFFF
Constants | |
---|---|
int |
BLACK
|
int |
BLUE
|
int |
CYAN
|
int |
DKGRAY
|
int |
GRAY
|
int |
GREEN
|
int |
LTGRAY
|
int |
MAGENTA
|
int |
RED
|
int |
TRANSPARENT
|
int |
WHITE
|
int |
YELLOW
|
Public constructors | |
---|---|
Color()
|
Public methods | |
---|---|
static
int
|
HSVToColor(float[] hsv)
Convert HSV components to an ARGB color. |
static
int
|
HSVToColor(int alpha, float[] hsv)
Convert HSV components to an ARGB color. |
static
void
|
RGBToHSV(int red, int green, int blue, float[] hsv)
Convert RGB components to HSV. |
static
int
|
alpha(int color)
Return the alpha component of a color int. |
static
int
|
argb(int alpha, int red, int green, int blue)
Return a color-int from alpha, red, green, blue components. |
static
int
|
blue(int color)
Return the blue component of a color int. |
static
void
|
colorToHSV(int color, float[] hsv)
Convert the argb color to its HSV components. |
static
int
|
green(int color)
Return the green component of a color int. |
static
float
|
luminance(int color)
Returns the relative luminance of a color. |
static
int
|
parseColor(String colorString)
Parse the color string, and return the corresponding color-int. |
static
int
|
red(int color)
Return the red component of a color int. |
static
int
|
rgb(int red, int green, int blue)
Return a color-int from red, green, blue components. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
int HSVToColor (float[] hsv)
Convert HSV components to an ARGB color. Alpha set to 0xFF. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.
Parameters | |
---|---|
hsv |
float :
3 element array which holds the input HSV components. |
Returns | |
---|---|
int |
the resulting argb color |
int HSVToColor (int alpha, float[] hsv)
Convert HSV components to an ARGB color. The alpha component is passed through unchanged. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.
Parameters | |
---|---|
alpha |
int :
the alpha component of the returned argb color. |
hsv |
float :
3 element array which holds the input HSV components. |
Returns | |
---|---|
int |
the resulting argb color |
void RGBToHSV (int red, int green, int blue, float[] hsv)
Convert RGB components to HSV. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]
Parameters | |
---|---|
red |
int :
red component value [0..255] |
green |
int :
green component value [0..255] |
blue |
int :
blue component value [0..255] |
hsv |
float :
3 element array which holds the resulting HSV components.
|
int alpha (int color)
Return the alpha component of a color int. This is the same as saying color >>> 24
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
int |
int argb (int alpha, int red, int green, int blue)
Return a color-int from alpha, red, green, blue components. These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.
Parameters | |
---|---|
alpha |
int :
Alpha component [0..255] of the color |
red |
int :
Red component [0..255] of the color |
green |
int :
Green component [0..255] of the color |
blue |
int :
Blue component [0..255] of the color
|
Returns | |
---|---|
int |
int blue (int color)
Return the blue component of a color int. This is the same as saying color & 0xFF
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
int |
void colorToHSV (int color, float[] hsv)
Convert the argb color to its HSV components. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]
Parameters | |
---|---|
color |
int :
the argb color to convert. The alpha component is ignored. |
hsv |
float :
3 element array which holds the resulting HSV components.
|
int green (int color)
Return the green component of a color int. This is the same as saying (color >> 8) & 0xFF
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
int |
float luminance (int color)
Returns the relative luminance of a color.
Assumes sRGB encoding. Based on the formula for relative luminance defined in WCAG 2.0, W3C Recommendation 11 December 2008.
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
float |
a value between 0 (darkest black) and 1 (lightest white) |
int parseColor (String colorString)
Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are: #RRGGBB #AARRGGBB or one of the following names: 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.
Parameters | |
---|---|
colorString |
String
|
Returns | |
---|---|
int |
int red (int color)
Return the red component of a color int. This is the same as saying (color >> 16) & 0xFF
Parameters | |
---|---|
color |
int
|
Returns | |
---|---|
int |
int rgb (int red, int green, int blue)
Return a color-int from red, green, blue components. The alpha component is implicity 255 (fully opaque). These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.
Parameters | |
---|---|
red |
int :
Red component [0..255] of the color |
green |
int :
Green component [0..255] of the color |
blue |
int :
Blue component [0..255] of the color
|
Returns | |
---|---|
int |