GeezerVison is showing docs.oracle.com — Color (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
-
-
Constructor Summary
Constructors
| Constructor |
Description |
Color(ColorSpace cspace,
float[] components,
float alpha) |
Creates a color in the specified ColorSpace
with the color components specified in the float
array and the specified alpha.
|
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).
|
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).
|
Color(int rgb) |
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.
|
Color(int rgba,
boolean hasalpha) |
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.
|
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).
|
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).
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
Color |
brighter() |
Creates a new Color that is a brighter version of this
Color.
|
PaintContext |
createContext(ColorModel cm,
Rectangle r,
Rectangle2D r2d,
AffineTransform xform,
RenderingHints hints) |
Creates and returns a PaintContext used to
generate a solid color field pattern.
|
Color |
darker() |
Creates a new Color that is a darker version of this
Color.
|
static Color |
decode(String nm) |
Converts a String to an integer and returns the
specified opaque Color.
|
boolean |
equals(Object obj) |
Determines whether another object is equal to this
Color.
|
int |
getAlpha() |
Returns the alpha component in the range 0-255.
|
int |
getBlue() |
Returns the blue component in the range 0-255 in the default sRGB
space.
|
static Color |
getColor(String nm) |
Finds a color in the system properties.
|
static Color |
getColor(String nm,
Color v) |
Finds a color in the system properties.
|
static Color |
getColor(String nm,
int v) |
Finds a color in the system properties.
|
float[] |
getColorComponents(ColorSpace cspace,
float[] compArray) |
Returns a float array containing only the color
components of the Color in the
ColorSpace specified by the cspace
parameter.
|
float[] |
getColorComponents(float[] compArray) |
Returns a float array containing only the color
components of the Color, in the
ColorSpace of the Color.
|
ColorSpace |
getColorSpace() |
Returns the ColorSpace of this Color.
|
float[] |
getComponents(ColorSpace cspace,
float[] compArray) |
Returns a float array containing the color and alpha
components of the Color, in the
ColorSpace specified by the cspace
parameter.
|
float[] |
getComponents(float[] compArray) |
Returns a float array containing the color and alpha
components of the Color, in the
ColorSpace of the Color.
|
int |
getGreen() |
Returns the green component in the range 0-255 in the default sRGB
space.
|
static Color |
getHSBColor(float h,
float s,
float b) |
Creates a Color object based on the specified values
for the HSB color model.
|
int |
getRed() |
Returns the red component in the range 0-255 in the default sRGB
space.
|
int |
getRGB() |
Returns the RGB value representing the color in the default sRGB
ColorModel.
|
float[] |
getRGBColorComponents(float[] compArray) |
Returns a float array containing only the color
components of the Color, in the default sRGB color
space.
|
float[] |
getRGBComponents(float[] compArray) |
Returns a float array containing the color and alpha
components of the Color, as represented in the default
sRGB color space.
|
int |
getTransparency() |
Returns the transparency mode for this Color.
|
int |
hashCode() |
Computes the hash code for this Color.
|
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.
|
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.
|
String |
toString() |
Returns a string representation of this Color.
|
-
-
Constructor Detail
-
Color
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 is defaulted to 255.
- Parameters:
r - the red component
g - the green component
b - the blue component
- Throws:
IllegalArgumentException - if r, g
or b are outside of the range
0 to 255, inclusive
- See Also:
getRed(),
getGreen(),
getBlue(),
getRGB()
-
Color
@ConstructorProperties(value={"red","green","blue","alpha"})
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).
- Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
- Throws:
IllegalArgumentException - if r, g,
b or a are outside of the range
0 to 255, inclusive
- See Also:
getRed(),
getGreen(),
getBlue(),
getAlpha(),
getRGB()
-
Color
public Color(int rgb)
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.
- Parameters:
rgb - the combined RGB components
- See Also:
ColorModel.getRGBdefault(),
getRed(),
getGreen(),
getBlue(),
getRGB()
-
Color
public Color(int rgba,
boolean hasalpha)
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.
- Parameters:
rgba - the combined RGBA components
hasalpha - true if the alpha bits are valid;
false otherwise
- See Also:
ColorModel.getRGBdefault(),
getRed(),
getGreen(),
getBlue(),
getAlpha(),
getRGB()
-
Color
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 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.
- Parameters:
r - the red component
g - the green component
b - the blue component
- Throws:
IllegalArgumentException - if r, g
or b are outside of the range
0.0 to 1.0, inclusive
- See Also:
getRed(),
getGreen(),
getBlue(),
getRGB()
-
Color
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.
- Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
- Throws:
IllegalArgumentException - if r, g
b or a are outside of the range
0.0 to 1.0, inclusive
- See Also:
getRed(),
getGreen(),
getBlue(),
getAlpha(),
getRGB()
-
Color
public Color(ColorSpace cspace,
float[] components,
float alpha)
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.
- Parameters:
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
- Throws:
IllegalArgumentException - if any of the values in the
components array or alpha is
outside of the range 0.0 to 1.0
- See Also:
getComponents(float[]),
getColorComponents(float[])
-
Method Detail
-
getRGB
public int getRGB()
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).
- Returns:
- the RGB value of the color in the default sRGB
ColorModel.
- Since:
- JDK1.0
- See Also:
ColorModel.getRGBdefault(),
getRed(),
getGreen(),
getBlue()
-
brighter
public Color brighter()
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.
The alpha value is preserved.
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.
- Returns:
- a new
Color object that is
a brighter version of this Color
with the same alpha value.
- Since:
- JDK1.0
- See Also:
darker()
-
darker
public Color darker()
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.
The alpha value is preserved.
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.
- Returns:
- a new
Color object that is
a darker version of this Color
with the same alpha value.
- Since:
- JDK1.0
- See Also:
brighter()
-
decode
public static Color decode(String nm)
throws NumberFormatException
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.
- Parameters:
nm - a String that represents
an opaque color as a 24-bit integer
- Returns:
- the new
Color object.
- Throws:
NumberFormatException - if the specified string cannot
be interpreted as a decimal,
octal, or hexadecimal integer.
- Since:
- JDK1.1
- See Also:
Integer.decode(java.lang.String)
-
getRGBComponents
public float[] getRGBComponents(float[] compArray)
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.
- Parameters:
compArray - an array that this method fills with
color and alpha components and returns
- Returns:
- the RGBA components in a
float array.
-
getRGBColorComponents
public float[] getRGBColorComponents(float[] compArray)
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.
- Parameters:
compArray - an array that this method fills with color
components and returns
- Returns:
- the RGB components in a
float array.
-
getComponents
public float[] getComponents(float[] compArray)
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.
- Parameters:
compArray - an array that this method fills with the color and
alpha components of this Color in its
ColorSpace and returns
- Returns:
- the color and alpha components in a
float
array.
-
getColorComponents
public float[] getColorComponents(float[] compArray)
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.
- Parameters:
compArray - an array that this method fills with the color
components of this Color in its
ColorSpace and returns
- Returns:
- the color components in a
float array.
-
getComponents
public float[] getComponents(ColorSpace cspace,
float[] compArray)
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.
- Parameters:
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
- Returns:
- the color and alpha components in a
float
array.
-
getColorComponents
public float[] getColorComponents(ColorSpace cspace,
float[] compArray)
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.
- Parameters:
cspace - a specified ColorSpace
compArray - an array that this method fills with the color
components of this Color in the specified
ColorSpace
- Returns:
- the color components in a
float array.
-
createContext
public PaintContext createContext(ColorModel cm,
Rectangle r,
Rectangle2D r2d,
AffineTransform xform,
RenderingHints hints)
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.
- Specified by:
createContext in interface Paint
- Parameters:
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.
- Returns:
- the
PaintContext for
generating color patterns.
- See Also:
Paint,
PaintContext,
ColorModel,
Rectangle,
Rectangle2D,
AffineTransform,
RenderingHints
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|