public class Color
extends Object
| java.lang.Object | |
| android.graphics.Color | |
Color类定义了用于创建和转换颜色整数的方法。 颜色表示为压缩整数,由4个字节组成:阿尔法,红色,绿色,蓝色。 这些值是无预失真的,意味着任何透明度都只存储在alpha分量中,而不存储在颜色分量中。 组件存储如下(alpha << 24)| (红色<< 16)| (绿色“8”) 蓝色。 每个组件的范围介于0..255之间,0代表该组件无贡献,255代表100%贡献。 因此,不透明黑色将是0xFF000000(100%不透明,但没有来自红色,绿色或蓝色的贡献),并且不透明白色将是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) 将HSV组件转换为ARGB颜色。 |
static int |
HSVToColor(int alpha, float[] hsv) 将HSV组件转换为ARGB颜色。 |
static void |
RGBToHSV(int red, int green, int blue, float[] hsv) 将RGB组件转换为HSV。 |
static int |
alpha(int color) 返回一个int类型的alpha分量。 |
static int |
argb(int alpha, int red, int green, int blue) 从alpha,红色,绿色,蓝色组件返回一个color-int。 |
static int |
blue(int color) 返回一个int类型的蓝色分量。 |
static void |
colorToHSV(int color, float[] hsv) 将argb颜色转换为其HSV组件。 |
static int |
green(int color) 返回颜色int的绿色组件。 |
static float |
luminance(int color) 返回颜色的相对亮度。 |
static int |
parseColor(String colorString) 解析颜色字符串,并返回相应的color-int。 |
static int |
red(int color) 返回一个int类型的红色分量。 |
static int |
rgb(int red, int green, int blue) 从红色,绿色,蓝色组件返回一个color-int。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
int HSVToColor (float[] hsv)
将HSV组件转换为ARGB颜色。 Alpha设置为0xFF。 hsv [0]是Hue [0 .. 360] hsv [1]是饱和度[0 ... 1] hsv [2]是值[0 ... 1]如果hsv值超出范围,它们被锁定。
| 参数(Parameters) | |
|---|---|
hsv |
float: 3 element array which holds the input HSV components. |
| 返回(Returns) | |
|---|---|
int |
the resulting argb color |
int HSVToColor (int alpha,
float[] hsv)
将HSV组件转换为ARGB颜色。 alpha分量不变。 hsv [0]是Hue [0 .. 360] hsv [1]是饱和度[0 ... 1] hsv [2]是值[0 ... 1]如果hsv值超出范围,它们被锁定。
| 参数(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)
将RGB组件转换为HSV。 hsv [0]是Hue [0 .. 360] hsv [1]是饱和度[0 ... 1] hsv [2]是值[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)
返回一个int类型的alpha分量。 这与说色彩相同>>> 24
| 参数(Parameters) | |
|---|---|
color |
int
|
| 返回(Returns) | |
|---|---|
int |
|
int argb (int alpha,
int red,
int green,
int blue)
从alpha,红色,绿色,蓝色组件返回一个color-int。 这些组件值应该是[0..255],但是没有执行范围检查,所以如果它们超出范围,则返回的颜色是未定义的。
| 参数(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)
返回一个int类型的蓝色分量。 这与说色和0xFF是一样的
| 参数(Parameters) | |
|---|---|
color |
int
|
| 返回(Returns) | |
|---|---|
int |
|
void colorToHSV (int color,
float[] hsv)
将argb颜色转换为其HSV组件。 hsv [0]是Hue [0 .. 360] hsv [1]是饱和度[0 ... 1] hsv [2]是值[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)
返回颜色int的绿色组件。 这与说(颜色>> 8)&0xFF相同
| 参数(Parameters) | |
|---|---|
color |
int
|
| 返回(Returns) | |
|---|---|
int |
|
float luminance (int color)
返回颜色的相对亮度。
假定sRGB编码。 基于WCAG 2.0中定义的相对亮度公式,W3C推荐标准2008年12月11日。
| 参数(Parameters) | |
|---|---|
color |
int
|
| 返回(Returns) | |
|---|---|
float |
a value between 0 (darkest black) and 1 (lightest white) |
int parseColor (String colorString)
解析颜色字符串,并返回相应的color-int。 如果字符串不能被解析,则抛出一个IllegalArgumentException异常。 支持的格式为:#RRGGBB #AARRGGBB或以下名称之一:'红','蓝','绿','黑','白','灰色','青色','洋红色','黄色' ,'灰色','暗灰色','灰色','lightgrey','darkgrey','aqua','fuchsia','lime','栗色','藏青色','橄榄色','紫色'银','深青色'。
| 参数(Parameters) | |
|---|---|
colorString |
String
|
| 返回(Returns) | |
|---|---|
int |
|
int red (int color)
返回一个int类型的红色分量。 这与说(颜色>> 16)&0xFF相同
| 参数(Parameters) | |
|---|---|
color |
int
|
| 返回(Returns) | |
|---|---|
int |
|
int rgb (int red,
int green,
int blue)
从红色,绿色,蓝色组件返回一个color-int。 alpha分量隐含255(完全不透明)。 这些组件值应该是[0..255],但是没有执行范围检查,所以如果它们超出范围,则返回的颜色是未定义的。
| 参数(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 |
|