This class encapsulates colors using the RGB format. In RGB
format, the red, blue, and green components of a color are each
represented by an integer in the range 0-255. The value 0
indicates no contribution from this primary color. The value 255
indicates the maximum intensity of this color component.
Although the Color class is based on the
three-component RGB model, the class provides a set of convenience
methods for converting between RGB and HSB colors. For a
definition of the RGB and HSB color models, see Foley, van Dam,
Feiner, and Hughes, Computer Graphics: Principles
and Practice.
Creates a color with the specified RGB value, where the red
component is in bits 16-23 of the argument, the green
component is in bits 8-15 of the argument, and the blue
component is in bits 0-7.
Converts the components of a color, as specified by the RGB
model, to an equivalent set of values for hue, saturation, and
brightness, the three components of the HSB model.
Creates a color with the specified RGB value, where the red
component is in bits 16-23 of the argument, the green
component is in bits 8-15 of the argument, and the blue
component is in bits 0-7. The value zero indicates no
contribution from the primary color component.
The actual color used in rendering depends on finding the best
match given the color space available for a given output device.
Parameters:
rgb - an integer giving the red, green, and blue components.
Creates a color with the specified red, green, and blue values,
where each of the values is in the range 0.0-1.0. The value
0.0 indicates no contribution from the primary color component.
The value 1.0 indicates the maximum intensity of the primary color
component.
The actual color used in rendering depends on finding the best
match given the color space available for a given output device.
Gets the RGB value representing the color in the default RGB ColorModel.
The red, green, and blue components of the color are each scaled to be
a value between 0 (abscence of the color) and 255 (complete saturation).
Bits 24-31 of the returned integer are 0xff, bits 16-23 are the red
value, bit 8-15 are the green value, and bits 0-7 are the blue value.
This method applies an arbitrary scale factor to each of the three RGB
components of the color to create a brighter version of the same
color. Although brighter and darker are
inverse operations, the results of a series of invocations of
these two methods may be inconsistent because of rounding errors.
Returns:
a new Color object,
a brighter version of this color.
This method applies an arbitrary scale factor to each of the three RGB
components of the color to create a darker version of the same
color. Although brighter and darker are
inverse operations, the results of a series of invocations of
these two methods may be inconsistent because of rounding errors.
Returns:
a new Color object,
a darker version of this color.
Converts a string to an integer and returns the
specified color. This method handles string formats that
are used to represent octal and hexidecimal numbers.
Parameters:
nm - a string that represents
a color as a 24-bit integer.
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.
If the specified property is not found, or could not be parsed as
an integer, then null is returned.
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.
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.
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.
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.
HSBtoRGB
public static int HSBtoRGB(float hue,
float saturation,
float brightness)
Converts the components of a color, as specified by the HSB
model, to an equivalent set of values for the RGB model.
The integer that is returned by HSBtoRGB encodes the
value of a color in bits 0&endash;23 of an integer value, the same
format used by the method getRGB. This integer can be
supplied as an argument to the Color constructor that
takes a single integer argument.
Parameters:
hue - the hue component of the color.
saturation - the saturation of the color.
brightness - the brightness of the color.
Returns:
the RGB value of the color with the indicated hue,
saturation, and brightness.
RGBtoHSB
public static float[] RGBtoHSB(int r,
int g,
int b,
float hsbvals[])
Converts the components of a color, as specified by the RGB
model, to an equivalent set of values for hue, saturation, and
brightness, 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.
Parameters:
r - the red component of the color.
g - the green component of the color.
b - the blue component of the color.
hsbvals - the array to be used to return the
three HSB values, or null.
Returns:
an array of three elements containing the hue, saturation,
and brightness (in that order), of the color with
the indicated red, green, and blue components.