java.lang.Object | |
↳ | java.awt.Color |
Known Direct Subclasses |
Known Indirect Subclasses |
The Color
class is used to encapsulate colors in the default
sRGB color space or colors in arbitrary color spaces identified by a
ColorSpace
. Every color has an implicit alpha value of 1.0 or
an explicit one provided in the constructor. The alpha value
defines the transparency of a color and can be represented by
a float value in the range 0.0 - 1.0 or 0 - 255.
An alpha value of 1.0 or 255 means that the color is completely
opaque and an alpha value of 0 or 0.0 means that the color is
completely transparent.
When constructing a Color
with an explicit alpha or
getting the color/alpha components of a Color
, the color
components are never premultiplied by the alpha component.
The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
java.awt.Transparency
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BLACK | The color black. | ||||||||||
BLUE | The color blue. | ||||||||||
CYAN | The color cyan. | ||||||||||
DARK_GRAY | The color dark gray. | ||||||||||
GRAY | The color gray. | ||||||||||
GREEN | The color green. | ||||||||||
LIGHT_GRAY | The color light gray. | ||||||||||
MAGENTA | The color magenta. | ||||||||||
ORANGE | The color orange. | ||||||||||
PINK | The color pink. | ||||||||||
RED | The color red. | ||||||||||
WHITE | The color white. | ||||||||||
YELLOW | The color yellow. | ||||||||||
black | The color black. | ||||||||||
blue | The color blue. | ||||||||||
cyan | The color cyan. | ||||||||||
darkGray | The color dark gray. | ||||||||||
gray | The color gray. | ||||||||||
green | The color green. | ||||||||||
lightGray | The color light gray. | ||||||||||
magenta | The color magenta. | ||||||||||
orange | The color orange. | ||||||||||
pink | The color pink. | ||||||||||
red | The color red. | ||||||||||
white | The color white. | ||||||||||
yellow | The color yellow. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an opaque sRGB color with the specified red, green,
and blue values in the range (0 - 255).
| |||||||||||
Creates an sRGB color with the specified red, green, blue, and alpha
values in the range (0 - 255).
| |||||||||||
Creates an opaque sRGB color with the specified combined RGB value
consisting of the red component in bits 16-23, the green component
in bits 8-15, and the blue component in bits 0-7.
| |||||||||||
Creates an sRGB color with the specified combined RGBA value consisting
of the alpha component in bits 24-31, the red component in bits 16-23,
the green component in bits 8-15, and the blue component in bits 0-7.
| |||||||||||
Creates an opaque sRGB color with the specified red, green, and blue
values in the range (0.0 - 1.0).
| |||||||||||
Creates an sRGB color with the specified red, green, blue, and
alpha values in the range (0.0 - 1.0).
| |||||||||||
Creates a color in the specified
ColorSpace
with the color components specified in the float
array and the specified alpha. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts the components of a color, as specified by the HSB
model, to an equivalent set of values for the default RGB model.
| |||||||||||
Converts the components of a color, as specified by the default RGB
model, to an equivalent set of values for hue, saturation, and
brightness that are the three components of the HSB model.
| |||||||||||
Creates a new
Color that is a brighter version of this
Color . | |||||||||||
Creates and returns a
PaintContext used to
generate a solid color field pattern. | |||||||||||
Creates a new
Color that is a darker version of this
Color . | |||||||||||
Converts a
String to an integer and returns the
specified opaque Color . | |||||||||||
Determines whether another object is equal to this
Color . | |||||||||||
Returns the alpha component in the range 0-255.
| |||||||||||
Returns the blue component in the range 0-255 in the default sRGB
space.
| |||||||||||
Finds a color in the system properties.
| |||||||||||
Finds a color in the system properties.
| |||||||||||
Finds a color in the system properties.
| |||||||||||
Returns a
float array containing only the color
components of the Color in the
ColorSpace specified by the cspace
parameter. | |||||||||||
Returns a
float array containing only the color
components of the Color , in the
ColorSpace of the Color . | |||||||||||
Returns the
ColorSpace of this Color . | |||||||||||
Returns a
float array containing the color and alpha
components of the Color , in the
ColorSpace of the Color . | |||||||||||
Returns a
float array containing the color and alpha
components of the Color , in the
ColorSpace specified by the cspace
parameter. | |||||||||||
Returns the green component in the range 0-255 in the default sRGB
space.
| |||||||||||
Creates a
Color object based on the specified values
for the HSB color model. | |||||||||||
Returns the RGB value representing the color in the default sRGB
ColorModel . | |||||||||||
Returns a
float array containing only the color
components of the Color , in the default sRGB color
space. | |||||||||||
Returns a
float array containing the color and alpha
components of the Color , as represented in the default
sRGB color space. | |||||||||||
Returns the red component in the range 0-255 in the default sRGB
space.
| |||||||||||
Returns the transparency mode for this
Color . | |||||||||||
Computes the hash code for this
Color . | |||||||||||
Returns a string representation of this
Color . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.awt.Paint
| |||||||||||
From interface
java.awt.Transparency
|
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a given output device. Alpha is defaulted to 255.
r | the red component |
---|---|
g | the green component |
b | the blue component |
IllegalArgumentException | if r , g
or b are outside of the range
0 to 255, inclusive |
---|
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
r | the red component |
---|---|
g | the green component |
b | the blue component |
a | the alpha component |
IllegalArgumentException | if r , g ,
b or a are outside of the range
0 to 255, inclusive |
---|
Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.
rgb | the combined RGB components |
---|
Creates an sRGB color with the specified combined RGBA value consisting
of the alpha component in bits 24-31, the red component in bits 16-23,
the green component in bits 8-15, and the blue component in bits 0-7.
If the hasalpha
argument is false
, alpha
is defaulted to 255.
rgba | the combined RGBA components |
---|---|
hasalpha | true if the alpha bits are valid;
false otherwise |
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). Alpha is defaulted to 1.0. The actual color used in rendering depends on finding the best match given the color space available for a particular output device.
r | the red component |
---|---|
g | the green component |
b | the blue component |
IllegalArgumentException | if r , g
or b are outside of the range
0.0 to 1.0, inclusive |
---|
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.
r | the red component |
---|---|
g | the green component |
b | the blue component |
a | the alpha component |
IllegalArgumentException | if r , g
b or a are outside of the range
0.0 to 1.0, inclusive |
---|
Creates a color in the specified ColorSpace
with the color components specified in the float
array and the specified alpha. The number of components is
determined by the type of the ColorSpace
. For
example, RGB requires 3 components, but CMYK requires 4
components.
cspace | the ColorSpace to be used to
interpret the components |
---|---|
components | an arbitrary number of color components
that is compatible with the ColorSpace |
alpha | alpha value |
IllegalArgumentException | if any of the values in the
components array or alpha is
outside of the range 0.0 to 1.0 |
---|
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
The saturation
and brightness
components
should be floating-point values between zero and one
(numbers in the range 0.0-1.0). The hue
component
can be any floating-point number. The floor of this number is
subtracted from it to create a fraction between 0 and 1. This
fractional number is then multiplied by 360 to produce the hue
angle in the HSB color model.
The integer that is returned by HSBtoRGB
encodes the
value of a color in bits 0-23 of an integer value that is the same
format used by the method
.
This integer can be supplied as an argument to the
getRGB
Color
constructor that takes a single integer argument.
hue | the hue component of the color |
---|---|
saturation | the saturation of the color |
brightness | the brightness of the color |
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.
If the hsbvals
argument is null
, then a
new array is allocated to return the result. Otherwise, the method
returns the array hsbvals
, with the values put into
that array.
r | the red component of the color |
---|---|
g | the green component of the color |
b | the blue component of the color |
hsbvals | the array used to return the
three HSB values, or null |
Creates a new Color
that is a brighter version of this
Color
.
This method applies an arbitrary scale factor to each of the three RGB
components of this Color
to create a brighter version
of this Color
. Although brighter
and
darker
are inverse operations, the results of a
series of invocations of these two methods might be inconsistent
because of rounding errors.
Color
object that is
a brighter version of this Color
.Creates and returns a PaintContext
used to
generate a solid color field pattern.
See the specification
of the
method in the Paint
interface for information
on null parameter handling.
cm | the preferred ColorModel which represents the most convenient
format for the caller to receive the pixel data, or null
if there is no preference. |
---|---|
r | the device space bounding box of the graphics primitive being rendered. |
r2d | the user space bounding box of the graphics primitive being rendered. |
xform | the AffineTransform from user
space into device space. |
hints | the set of hints that the context object can use to choose between rendering alternatives. |
PaintContext
for
generating color patterns.Creates a new Color
that is a darker version of this
Color
.
This method applies an arbitrary scale factor to each of the three RGB
components of this Color
to create a darker version of
this Color
. Although brighter
and
darker
are inverse operations, the results of a series
of invocations of these two methods might be inconsistent because
of rounding errors.
Color
object that is
a darker version of this Color
.Converts a String
to an integer and returns the
specified opaque Color
. This method handles string
formats that are used to represent octal and hexadecimal numbers.
nm | a String that represents
an opaque color as a 24-bit integer |
---|
Color
object.NumberFormatException | if the specified string cannot be interpreted as a decimal, octal, or hexadecimal integer. |
---|
Determines whether another object is equal to this
Color
.
The result is true
if and only if the argument is not
null
and is a Color
object that has the same
red, green, blue, and alpha values as this object.
obj | the object to test for equality with this
Color |
---|
true
if the objects are the same;
false
otherwise.Returns the blue component in the range 0-255 in the default sRGB space.
Finds a color in the system properties.
The first argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as
an integer then the integer value v
is used instead,
and is converted to a Color
object.
nm | the name of the color property |
---|---|
v | the default color value, as an integer |
Color
converted from the system
property or the Color
converted from
the specified integer.Finds a color in the system properties.
The first argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or cannot be parsed as
an integer then the Color
specified by the second
argument is returned instead.
nm | the name of the color property |
---|---|
v | the default Color |
Color
converted from the system
property, or the specified Color
.Finds a color in the system properties.
The argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as
an integer then null
is returned.
nm | the name of the color property |
---|
Color
converted from the system
property.Returns a float
array containing only the color
components of the Color
in the
ColorSpace
specified by the cspace
parameter. If compArray
is null
, an array
with length equal to the number of components in
cspace
is created for the return value. Otherwise,
compArray
must have at least this length, and it is
filled in with the components and returned.
cspace | a specified ColorSpace |
---|---|
compArray | an array that this method fills with the color
components of this Color in the specified
ColorSpace |
float
array.
Returns a float
array containing only the color
components of the Color
, in the
ColorSpace
of the Color
.
If compArray
is null
, an array with
length equal to the number of components in the associated
ColorSpace
is created for
the return value. Otherwise, compArray
must have at
least this length and it is filled in with the components and
returned.
compArray | an array that this method fills with the color
components of this Color in its
ColorSpace and returns |
---|
float
array.
Returns the ColorSpace
of this Color
.
Color
object's ColorSpace
.
Returns a float
array containing the color and alpha
components of the Color
, in the
ColorSpace
of the Color
.
If compArray
is null
, an array with
length equal to the number of components in the associated
ColorSpace
plus one is created for
the return value. Otherwise, compArray
must have at
least this length and it is filled in with the components and
returned.
compArray | an array that this method fills with the color and
alpha components of this Color in its
ColorSpace and returns |
---|
float
array.
Returns a float
array containing the color and alpha
components of the Color
, in the
ColorSpace
specified by the cspace
parameter. If compArray
is null
, an
array with length equal to the number of components in
cspace
plus one is created for the return value.
Otherwise, compArray
must have at least this
length, and it is filled in with the components and returned.
cspace | a specified ColorSpace |
---|---|
compArray | an array that this method fills with the
color and alpha components of this Color in
the specified ColorSpace and returns |
float
array.
Returns the green component in the range 0-255 in the default sRGB space.
Creates a Color
object based on the specified values
for the HSB color model.
The s
and b
components should be
floating-point values between zero and one
(numbers in the range 0.0-1.0). The h
component
can be any floating-point number. The floor of this number is
subtracted from it to create a fraction between 0 and 1. This
fractional number is then multiplied by 360 to produce the hue
angle in the HSB color model.
h | the hue component |
---|---|
s | the saturation of the color |
b | the brightness of the color |
Color
object with the specified hue,
saturation, and brightness.Returns the RGB value representing the color in the default sRGB
ColorModel
.
(Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are
blue).
ColorModel
.Returns a float
array containing only the color
components of the Color
, in the default sRGB color
space. If compArray
is null
, an array of
length 3 is created for the return value. Otherwise,
compArray
must have length 3 or greater, and it is
filled in with the components and returned.
compArray | an array that this method fills with color components and returns |
---|
float
array.
Returns a float
array containing the color and alpha
components of the Color
, as represented in the default
sRGB color space.
If compArray
is null
, an array of length
4 is created for the return value. Otherwise,
compArray
must have length 4 or greater,
and it is filled in with the components and returned.
compArray | an array that this method fills with color and alpha components and returns |
---|
float
array.
Returns the red component in the range 0-255 in the default sRGB space.
Returns the transparency mode for this Color
. This is
required to implement the Paint
interface.
Color
object's transparency mode.Computes the hash code for this Color
.
Returns a string representation of this Color
. This
method is intended to be used only for debugging purposes. The
content and format of the returned string might vary between
implementations. The returned string might be empty but cannot
be null
.
Color
.