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 .
ColorSpace, AlphaComposite
| Modifier and Type | Field and Description |
|---|---|
| public static final Color | black
The color black. |
| public static final Color | BLACK
The color black. |
| public static final Color | blue
The color blue. |
| public static final Color | BLUE
The color blue. |
| private ColorSpace | cs
The |
| public static final Color | cyan
The color cyan. |
| public static final Color | CYAN
The color cyan. |
| public static final Color | DARK_GRAY
The color dark gray. |
| public static final Color | darkGray
The color dark gray. |
| private static final double | |
| private float | falpha
The alpha value as a |
| private float[] | frgbvalue
The color value in the default sRGB |
| private float[] | fvalue
The color value in the native |
| public static final Color | gray
The color gray. |
| public static final Color | GRAY
The color gray. |
| public static final Color | green
The color green. |
| public static final Color | GREEN
The color green. |
| public static final Color | LIGHT_GRAY
The color light gray. |
| public static final Color | lightGray
The color light gray. |
| public static final Color | magenta
The color magenta. |
| public static final Color | MAGENTA
The color magenta. |
| public static final Color | orange
The color orange. |
| public static final Color | ORANGE
The color orange. |
| public static final Color | pink
The color pink. |
| public static final Color | PINK
The color pink. |
| public static final Color | red
The color red. |
| public static final Color | RED
The color red. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability. |
| pack-priv int | value
The color value. |
| public static final Color | white
The color white. |
| public static final Color | WHITE
The color white. |
| public static final Color | yellow
The color yellow. |
| public static final Color | YELLOW
The color yellow. |
| Access | Constructor and Description |
|---|---|
| public | Color(int
the red component r, int the green component g, int the blue component b)Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). |
| public | Color(int
the red component r, int the green component g, int the blue component b, int the alpha component a)Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255). |
| public | Color(int
the combined RGB components rgb)Creates an opaque sRGB color with the specified RGB value consisting of
|
| public | Color(int
the combined ARGB components argb, boolean true if the alpha bits are valid;
false otherwiseCreates an sRGB color with the specified ARGB value consisting of
|
| public | Color(float
the red component r, float the green component g, float the blue component b)Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). |
| public | Color(float
the red component r, float the green component g, float the blue component b, float the alpha component a)Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). |
| public | Color(ColorSpace
the cspace, float[] ColorSpace to be used to
interpret the componentsan arbitrary number of color components
that is compatible with the components, float ColorSpacealpha value alpha)Creates a color in the specified |
| Modifier and Type | Method and Description |
|---|---|
| public Color | Returns: a newColor object that is
a brighter version of this Color
with the same alpha value.Creates a new |
| public PaintContext | Returns: thePaintContext for
generating color patterns.the preferred cm, Rectangle ColorModel which represents the most convenient
format for the caller to receive the pixel data, or null
if there is no preference.the device space bounding box
of the graphics primitive being rendered. r, Rectangle2D the user space bounding box
of the graphics primitive being rendered. r2d, AffineTransform the xform, RenderingHints AffineTransform from user
space into device space.the set of hints that the context object can use to
choose between rendering alternatives. hints)Implements java. Creates and returns a |
| public Color | Returns: a newColor object that is
a darker version of this Color
with the same alpha value.Creates a new |
| public static Color | |
| public boolean | Returns: true if the objects are the same;
false otherwise.the object to test for equality with this
obj)ColorOverrides java. Determines whether another object is equal to this
|
| public int | |
| public int | Returns: the blue component.Returns the blue component in the range 0-255 in the default sRGB space. |
| public static Color | |
| public static Color | |
| public static Color | |
| public float[] | Returns: the color components in afloat array.an array that this method fills with the color
components of this compArray)Color in its
ColorSpace and returnsReturns a |
| public float[] | Returns: the color components in afloat array.a specified cspace, float[] ColorSpacean array that this method fills with the color
components of this compArray)Color in the specified
ColorSpaceReturns a |
| public ColorSpace | |
| public float[] | Returns: the color and alpha components in afloat
array.an array that this method fills with the color and
alpha components of this compArray)Color in its
ColorSpace and returnsReturns a |
| public float[] | Returns: the color and alpha components in afloat
array.a specified cspace, float[] ColorSpacean array that this method fills with the
color and alpha components of this compArray)Color in
the specified ColorSpace and returnsReturns a |
| public int | Returns: the green component.Returns the green component in the range 0-255 in the default sRGB space. |
| public static Color | Returns: aColor object with the specified hue,
saturation, and brightness.the hue component h, float the saturation of the color s, float the brightness of the color b)Creates a |
| public int | Returns: the red component.Returns the red component in the range 0-255 in the default sRGB space. |
| public int | Returns: the RGB value of the color in the default sRGBColorModel.Returns the RGB value representing the color in the default sRGB
|
| public float[] | Returns: the RGB components in afloat array.an array that this method fills with color
components and returns compArray)Returns a |
| public float[] | Returns: the RGBA components in afloat array.an array that this method fills with
color and alpha components and returns compArray)Returns a |
| public int | Returns: thisColor object's transparency mode.Implements java. Returns the transparency mode for this |
| public int | Returns: a hash code value for this object.Overrides java. Computes the hash code for this |
| public static int | Returns: the RGB value of the color with the indicated hue, saturation, and brightness.the hue component of the color hue, float the saturation of the color saturation, float the brightness of the color brightness)Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model. |
| public static float[] | 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.the red component of the color r, int the green component of the color g, int the blue component of the color b, float[] the array used to return the
three HSB values, or hsbvals)nullConverts 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. |
| private static void | testColorValueRange(int
the Red component r, int the Green component g, int the Blue component b, int a)Checks the color integer components supplied for validity. |
| private static void | testColorValueRange(float
the Red component r, float the Green component g, float the Blue component b, float a)Checks the color |
| public String | Returns: a string representation of thisColor.Overrides java. Returns a string representation of this |
| black | back to summary |
|---|---|
| public static final Color black The color black. In the default sRGB space. | |
| BLACK | back to summary |
|---|---|
| public static final Color BLACK The color black. In the default sRGB space.
| |
| blue | back to summary |
|---|---|
| public static final Color blue The color blue. In the default sRGB space. | |
| BLUE | back to summary |
|---|---|
| public static final Color BLUE The color blue. In the default sRGB space.
| |
| cs | back to summary |
|---|---|
| private ColorSpace cs The
| |
| cyan | back to summary |
|---|---|
| public static final Color cyan The color cyan. In the default sRGB space. | |
| CYAN | back to summary |
|---|---|
| public static final Color CYAN The color cyan. In the default sRGB space.
| |
| DARK_GRAY | back to summary |
|---|---|
| public static final Color DARK_GRAY The color dark gray. In the default sRGB space.
| |
| darkGray | back to summary |
|---|---|
| public static final Color darkGray The color dark gray. In the default sRGB space. | |
| FACTOR | back to summary |
|---|---|
| private static final double FACTOR | |
| falpha | back to summary |
|---|---|
| private float falpha The alpha value as a
| |
| frgbvalue | back to summary |
|---|---|
| private float[] frgbvalue The color value in the default sRGB
| |
| fvalue | back to summary |
|---|---|
| private float[] fvalue The color value in the native
| |
| gray | back to summary |
|---|---|
| public static final Color gray The color gray. In the default sRGB space. | |
| GRAY | back to summary |
|---|---|
| public static final Color GRAY The color gray. In the default sRGB space.
| |
| green | back to summary |
|---|---|
| public static final Color green The color green. In the default sRGB space. | |
| GREEN | back to summary |
|---|---|
| public static final Color GREEN The color green. In the default sRGB space.
| |
| LIGHT_GRAY | back to summary |
|---|---|
| public static final Color LIGHT_GRAY The color light gray. In the default sRGB space.
| |
| lightGray | back to summary |
|---|---|
| public static final Color lightGray The color light gray. In the default sRGB space. | |
| magenta | back to summary |
|---|---|
| public static final Color magenta The color magenta. In the default sRGB space. | |
| MAGENTA | back to summary |
|---|---|
| public static final Color MAGENTA The color magenta. In the default sRGB space.
| |
| orange | back to summary |
|---|---|
| public static final Color orange The color orange. In the default sRGB space. | |
| ORANGE | back to summary |
|---|---|
| public static final Color ORANGE The color orange. In the default sRGB space.
| |
| pink | back to summary |
|---|---|
| public static final Color pink The color pink. In the default sRGB space. | |
| PINK | back to summary |
|---|---|
| public static final Color PINK The color pink. In the default sRGB space.
| |
| red | back to summary |
|---|---|
| public static final Color red The color red. In the default sRGB space. | |
| RED | back to summary |
|---|---|
| public static final Color RED The color red. In the default sRGB space.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.1 for interoperability. | |
| value | back to summary |
|---|---|
| pack-priv int value The color value.
| |
| white | back to summary |
|---|---|
| public static final Color white The color white. In the default sRGB space. | |
| WHITE | back to summary |
|---|---|
| public static final Color WHITE The color white. In the default sRGB space.
| |
| yellow | back to summary |
|---|---|
| public static final Color yellow The color yellow. In the default sRGB space. | |
| YELLOW | back to summary |
|---|---|
| public static final Color YELLOW The color yellow. In the default sRGB space.
| |
| Color | back to summary |
|---|---|
| public Color(int r, int g, int b) 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 defaults to 255.
| |
| Color | back to summary |
|---|---|
| public Color(int r, int g, int b, int a) Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
| |
| Color | back to summary |
|---|---|
| public Color(int rgb) Creates an opaque sRGB color with the specified RGB value consisting of
| |
| Color | back to summary |
|---|---|
| public Color(int argb, boolean hasAlpha) Creates an sRGB color with the specified ARGB value consisting of
hasAlpha argument is false, alpha defaults to 255.
| |
| Color | back to summary |
|---|---|
| public Color(float r, float g, float b) Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). Alpha defaults 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.
| |
| Color | back to summary |
|---|---|
| public Color(float r, float g, float b, float a) 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. | |
| Color | back to summary |
|---|---|
| public Color(ColorSpace cspace, float[] components, float alpha) Creates a color in the specified
| |
| brighter | back to summary |
|---|---|
| public Color brighter() Creates a new
This method applies an arbitrary scale factor to each of the three RGB
components of this
| |
| createContext | back to summary |
|---|---|
| public PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints) Implements java. Creates and returns a
| |
| darker | back to summary |
|---|---|
| public Color darker() Creates a new
This method applies an arbitrary scale factor to each of the three RGB
components of this
| |
| decode | back to summary |
|---|---|
| public static Color decode(String nm) throws NumberFormatException Converts a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Determines whether another object is equal to this
The result is
| |
| getAlpha | back to summary |
|---|---|
| public int getAlpha() Returns the alpha component in the range 0-255.
| |
| getBlue | back to summary |
|---|---|
| public int getBlue() Returns the blue component in the range 0-255 in the default sRGB space.
| |
| getColor | back to summary |
|---|---|
| public static Color getColor(String nm) 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
If the specified property is not found or could not be parsed as
an integer then
| |
| getColor | back to summary |
|---|---|
| public static Color getColor(String nm, Color v) 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
If the specified property is not found or cannot be parsed as
an integer then the
| |
| getColor | back to summary |
|---|---|
| public static Color getColor(String nm, int v) 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
If the specified property is not found or could not be parsed as
an integer then the integer value
| |
| getColorComponents | back to summary |
|---|---|
| public float[] getColorComponents(float[] compArray) Returns a
| |
| getColorComponents | back to summary |
|---|---|
| public float[] getColorComponents(ColorSpace cspace, float[] compArray) Returns a
| |
| getColorSpace | back to summary |
|---|---|
| public ColorSpace getColorSpace() Returns the
| |
| getComponents | back to summary |
|---|---|
| public float[] getComponents(float[] compArray) Returns a
| |
| getComponents | back to summary |
|---|---|
| public float[] getComponents(ColorSpace cspace, float[] compArray) Returns a
| |
| getGreen | back to summary |
|---|---|
| public int getGreen() Returns the green component in the range 0-255 in the default sRGB space.
| |
| getHSBColor | back to summary |
|---|---|
| public static Color getHSBColor(float h, float s, float b) Creates a
The
| |
| getRed | back to summary |
|---|---|
| public int getRed() Returns the red component in the range 0-255 in the default sRGB space.
| |
| getRGB | back to summary |
|---|---|
| public int getRGB() Returns the RGB value representing the color in the default sRGB
| |
| getRGBColorComponents | back to summary |
|---|---|
| public float[] getRGBColorComponents(float[] compArray) Returns a
| |
| getRGBComponents | back to summary |
|---|---|
| public float[] getRGBComponents(float[] compArray) Returns a
| |
| getTransparency | back to summary |
|---|---|
| public int getTransparency() Implements java. Returns the transparency mode for this
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Computes the hash code for this
| |
| HSBtoRGB | back to summary |
|---|---|
| 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 default RGB model.
The
The integer that is returned by
| |
| RGBtoHSB | back to summary |
|---|---|
| public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) 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
| |
| testColorValueRange | back to summary |
|---|---|
| private static void testColorValueRange(int r, int g, int b, int a) Checks the color integer components supplied for validity.
Throws an
| |
| testColorValueRange | back to summary |
|---|---|
| private static void testColorValueRange(float r, float g, float b, float a) Checks the color
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this
| |