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 contributes from red, gree, blue, and opaque-white would be 0xFFFFFFFF
Summary
Constants
|
|
|
Value |
|
int |
BLACK |
|
-16777216 |
0xff000000 |
int |
BLUE |
|
-16776961 |
0xff0000ff |
int |
CYAN |
|
-16711681 |
0xff00ffff |
int |
DKGRAY |
|
-12303292 |
0xff444444 |
int |
GRAY |
|
-7829368 |
0xff888888 |
int |
GREEN |
|
-16711936 |
0xff00ff00 |
int |
LTGRAY |
|
-3355444 |
0xffcccccc |
int |
MAGENTA |
|
-65281 |
0xffff00ff |
int |
RED |
|
-65536 |
0xffff0000 |
int |
TRANSPARENT |
|
0 |
0x00000000 |
int |
WHITE |
|
-1 |
0xffffffff |
int |
YELLOW |
|
-256 |
0xffffff00 |
Public Constructors
Public Methods
|
|
|
static |
|
int |
HSVToColor(int alpha, float[] hsv) |
|
|
|
static |
|
int |
HSVToColor(float[] hsv) |
|
|
|
static |
|
void |
RGBToHSV(int red, int green, int blue, float[] hsv) |
|
|
|
static |
|
int |
alpha(int color) |
|
|
|
static |
|
int |
argb(int alpha, int red, int green, int blue) |
|
|
|
static |
|
int |
blue(int color) |
|
|
|
static |
|
void |
colorToHSV(int color, float[] hsv) |
|
|
|
static |
|
int |
green(int color) |
|
|
|
static |
|
int |
parseColor(String colorString) |
|
|
|
static |
|
int |
red(int color) |
|
|
|
static |
|
int |
rgb(int red, int green, int blue) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
BLACK
Constant Value:
-16777216
(0xff000000)
public
static
final
int
BLUE
Constant Value:
-16776961
(0xff0000ff)
public
static
final
int
CYAN
Constant Value:
-16711681
(0xff00ffff)
public
static
final
int
DKGRAY
Constant Value:
-12303292
(0xff444444)
public
static
final
int
GRAY
Constant Value:
-7829368
(0xff888888)
public
static
final
int
GREEN
Constant Value:
-16711936
(0xff00ff00)
public
static
final
int
LTGRAY
Constant Value:
-3355444
(0xffcccccc)
public
static
final
int
MAGENTA
Constant Value:
-65281
(0xffff00ff)
public
static
final
int
RED
Constant Value:
-65536
(0xffff0000)
public
static
final
int
TRANSPARENT
Constant Value:
0
(0x00000000)
public
static
final
int
WHITE
Constant Value:
-1
(0xffffffff)
public
static
final
int
YELLOW
Constant Value:
-256
(0xffffff00)
Public Constructors
Public Methods
public
static
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
| the alpha component of the returned argb color. |
hsv
| 3 element array which holds the input HSV components. |
public
static
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
| 3 element array which holds the input HSV components. |
public
static
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
| red component value [0..255] |
green
| green component value [0..255] |
blue
| blue component value [0..255] |
hsv
| 3 element array which holds the resulting HSV components.
|
public
static
int
alpha(int color)
Return the alpha component of a color int. This is the same as saying
color >>> 24
public
static
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
| Alpha component [0..255] of the color |
red
| Red component [0..255] of the color |
green
| Green component [0..255] of the color |
blue
| Blue component [0..255] of the color
|
public
static
int
blue(int color)
Return the blue component of a color int. This is the same as saying
color & 0xFF
public
static
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
| the argb color to convert. The alpha component is ignored. |
hsv
| 3 element array which holds the resulting HSV components.
|
public
static
int
green(int color)
Return the green component of a color int. This is the same as saying
(color >> 8) & 0xFF
public
static
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
'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta',
'yellow', 'lightgray', 'darkgray'
public
static
int
red(int color)
Return the red component of a color int. This is the same as saying
(color >> 16) & 0xFF
public
static
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
| Red component [0..255] of the color |
green
| Green component [0..255] of the color |
blue
| Blue component [0..255] of the color
|