APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class Color

extends Object
implements Paint, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.awt.Paint, java.awt.Transparency
Known Direct Subclasses
java.awt.SystemColor, javax.swing.plaf.ColorUIResource, javax.swing.plaf.nimbus.DerivedColor
Imports
java.awt.color.ColorSpace, java.awt.geom.AffineTransform, .Rectangle2D, java.awt.image.ColorModel, java.beans.ConstructorProperties, java.io.Serial

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 .

Authors
Sami Shaio, Arthur van Hoff
Version
10 Feb 1997
See Also
ColorSpace, AlphaComposite

Field Summary

Modifier and TypeField 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 ColorSpace.

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 float component.

private float[]
frgbvalue

The color value in the default sRGB ColorSpace as float components (no alpha).

private float[]
fvalue

The color value in the native ColorSpace as float components (no alpha).

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.

Constructor Summary

AccessConstructor 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

  • the red component in bits 16-23,
  • the green component in bits 8-15, and
  • the blue component in bits 0-7.
public
Color(int
the combined ARGB components
argb
,
boolean
true if the alpha bits are valid; false otherwise
hasAlpha
)

Creates an sRGB color with the specified ARGB 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.
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 ColorSpace to be used to interpret the components
cspace
,
float[]
an arbitrary number of color components that is compatible with the ColorSpace
components
,
float
alpha value
alpha
)

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Method Summary

Modifier and TypeMethod and Description
public Color

Returns:

a new Color object that is a brighter version of this Color with the same alpha value.
brighter
()

Creates a new Color that is a brighter version of this Color.

public PaintContext

Returns:

the PaintContext for generating color patterns.
createContext
(ColorModel
the preferred ColorModel which represents the most convenient format for the caller to receive the pixel data, or null if there is no preference.
cm
,
Rectangle
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 AffineTransform from user space into device space.
xform
,
RenderingHints
the set of hints that the context object can use to choose between rendering alternatives.
hints
)

Implements java.awt.Paint.createContext.

Creates and returns a PaintContext used to generate a solid color field pattern.

public Color

Returns:

a new Color object that is a darker version of this Color with the same alpha value.
darker
()

Creates a new Color that is a darker version of this Color.

public static Color

Returns:

the new Color object.
decode
(String
a String that represents an opaque color as a 24-bit integer
nm
)

Converts a String to an integer and returns the specified opaque Color.

public boolean

Returns:

true if the objects are the same; false otherwise.
equals
(Object
the object to test for equality with this Color
obj
)

Overrides java.lang.Object.equals.

Determines whether another object is equal to this Color.

public int

Returns:

the alpha component.
getAlpha
()

Returns the alpha component in the range 0-255.

public int

Returns:

the blue component.
getBlue
()

Returns the blue component in the range 0-255 in the default sRGB space.

public static Color

Returns:

the Color converted from the system property.
getColor
(String
the name of the color property
nm
)

Finds a color in the system properties.

public static Color

Returns:

the Color converted from the system property, or the specified Color.
getColor
(String
the name of the color property
nm
,
Color
the default Color
v
)

Finds a color in the system properties.

public static Color

Returns:

the Color converted from the system property or the Color converted from the specified integer.
getColor
(String
the name of the color property
nm
,
int
the default color value, as an integer
v
)

Finds a color in the system properties.

public float[]

Returns:

the color components in a float array.
getColorComponents
(float[]
an array that this method fills with the color components of this Color in its ColorSpace and returns
compArray
)

Returns a float array containing only the color components of the Color, in the ColorSpace of the Color.

public float[]

Returns:

the color components in a float array.
getColorComponents
(ColorSpace
a specified ColorSpace
cspace
,
float[]
an array that this method fills with the color components of this Color in the specified ColorSpace
compArray
)

Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter.

public ColorSpace

Returns:

this Color object's ColorSpace.
getColorSpace
()

Returns the ColorSpace of this Color.

public float[]

Returns:

the color and alpha components in a float array.
getComponents
(float[]
an array that this method fills with the color and alpha components of this Color in its ColorSpace and returns
compArray
)

Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color.

public float[]

Returns:

the color and alpha components in a float array.
getComponents
(ColorSpace
a specified ColorSpace
cspace
,
float[]
an array that this method fills with the color and alpha components of this Color in the specified ColorSpace and returns
compArray
)

Returns a float array containing the color and alpha components of the Color, in the ColorSpace specified by the cspace parameter.

public int

Returns:

the green component.
getGreen
()

Returns the green component in the range 0-255 in the default sRGB space.

public static Color

Returns:

a Color object with the specified hue, saturation, and brightness.
getHSBColor
(float
the hue component
h
,
float
the saturation of the color
s
,
float
the brightness of the color
b
)

Creates a Color object based on the specified values for the HSB color model.

public int

Returns:

the red component.
getRed
()

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 sRGB ColorModel.
getRGB
()

Returns the RGB value representing the color in the default sRGB ColorModel, 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.
public float[]

Returns:

the RGB components in a float array.
getRGBColorComponents
(float[]
an array that this method fills with color components and returns
compArray
)

Returns a float array containing only the color components of the Color, in the default sRGB color space.

public float[]

Returns:

the RGBA components in a float array.
getRGBComponents
(float[]
an array that this method fills with color and alpha components and returns
compArray
)

Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space.

public int

Returns:

this Color object's transparency mode.
getTransparency
()

Implements java.awt.Transparency.getTransparency.

Returns the transparency mode for this Color.

public int

Returns:

a hash code value for this object.
hashCode
()

Overrides java.lang.Object.hashCode.

Computes the hash code for this Color.

public static int

Returns:

the RGB value of the color with the indicated hue, saturation, and brightness.
HSBtoRGB
(float
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.
RGBtoHSB
(int
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 null
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.

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 float components supplied for validity.

public String

Returns:

a string representation of this Color.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this Color.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

blackback to summary
public static final Color black

The color black. In the default sRGB space.

BLACKback to summary
public static final Color BLACK

The color black. In the default sRGB space.

Since
1.4
blueback to summary
public static final Color blue

The color blue. In the default sRGB space.

BLUEback to summary
public static final Color BLUE

The color blue. In the default sRGB space.

Since
1.4
csback to summary
private ColorSpace cs

The ColorSpace. If null, then it's default is sRGB.

See Also
getColor, getColorSpace, getColorComponents
cyanback to summary
public static final Color cyan

The color cyan. In the default sRGB space.

CYANback to summary
public static final Color CYAN

The color cyan. In the default sRGB space.

Since
1.4
DARK_GRAYback to summary
public static final Color DARK_GRAY

The color dark gray. In the default sRGB space.

Since
1.4
darkGrayback to summary
public static final Color darkGray

The color dark gray. In the default sRGB space.

FACTORback to summary
private static final double FACTOR
falphaback to summary
private float falpha

The alpha value as a float component. If frgbvalue is null, this is not valid data, so compute from the int color value.

See Also
getRGBComponents, getComponents
frgbvalueback to summary
private float[] frgbvalue

The color value in the default sRGB ColorSpace as float components (no alpha). If null after object construction, this must be an sRGB color constructed with 8-bit precision, so compute from the int color value.

See Also
getRGBColorComponents, getRGBComponents
fvalueback to summary
private float[] fvalue

The color value in the native ColorSpace as float components (no alpha). If null after object construction, this must be an sRGB color constructed with 8-bit precision, so compute from the int color value.

See Also
getRGBColorComponents, getRGBComponents
grayback to summary
public static final Color gray

The color gray. In the default sRGB space.

GRAYback to summary
public static final Color GRAY

The color gray. In the default sRGB space.

Since
1.4
greenback to summary
public static final Color green

The color green. In the default sRGB space.

GREENback to summary
public static final Color GREEN

The color green. In the default sRGB space.

Since
1.4
LIGHT_GRAYback to summary
public static final Color LIGHT_GRAY

The color light gray. In the default sRGB space.

Since
1.4
lightGrayback to summary
public static final Color lightGray

The color light gray. In the default sRGB space.

magentaback to summary
public static final Color magenta

The color magenta. In the default sRGB space.

MAGENTAback to summary
public static final Color MAGENTA

The color magenta. In the default sRGB space.

Since
1.4
orangeback to summary
public static final Color orange

The color orange. In the default sRGB space.

ORANGEback to summary
public static final Color ORANGE

The color orange. In the default sRGB space.

Since
1.4
pinkback to summary
public static final Color pink

The color pink. In the default sRGB space.

PINKback to summary
public static final Color PINK

The color pink. In the default sRGB space.

Since
1.4
redback to summary
public static final Color red

The color red. In the default sRGB space.

REDback to summary
public static final Color RED

The color red. In the default sRGB space.

Since
1.4
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
valueback to summary
pack-priv int value

The color value.

See Also
getRGB
whiteback to summary
public static final Color white

The color white. In the default sRGB space.

WHITEback to summary
public static final Color WHITE

The color white. In the default sRGB space.

Since
1.4
yellowback to summary
public static final Color yellow

The color yellow. In the default sRGB space.

YELLOWback to summary
public static final Color YELLOW

The color yellow. In the default sRGB space.

Since
1.4

Constructor Detail

Colorback 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.

Parameters
r:int

the red component

g:int

the green component

b:int

the blue component

Exceptions
IllegalArgumentException:
if r, g or b are outside of the range 0 to 255, inclusive
See Also
getRed, getGreen, getBlue, getRGB
Colorback 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).

Parameters
r:int

the red component

g:int

the green component

b:int

the blue component

a:int

the alpha component

Annotations
@ConstructorProperties:red, green, blue, alpha
Exceptions
IllegalArgumentException:
if r, g, b or a are outside of the range 0 to 255, inclusive
See Also
getRed, getGreen, getBlue, getAlpha, getRGB
Colorback to summary
public Color(int rgb)

Creates an opaque sRGB color with the specified 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 defaults to 255.
Parameters
rgb:int

the combined RGB components

See Also
java.awt.image.ColorModel#getRGBdefault, getRed, getGreen, getBlue, getRGB
Colorback to summary
public Color(int argb, boolean hasAlpha)

Creates an sRGB color with the specified ARGB 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 defaults to 255.
Parameters
argb:int

the combined ARGB components

hasAlpha:boolean

true if the alpha bits are valid; false otherwise

See Also
java.awt.image.ColorModel#getRGBdefault, getRed, getGreen, getBlue, getAlpha, getRGB
Colorback 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.

Parameters
r:float

the red component

g:float

the green component

b:float

the blue component

Exceptions
IllegalArgumentException:
if r, g or b are outside of the range 0.0 to 1.0, inclusive
See Also
getRed, getGreen, getBlue, getRGB
Colorback 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.

Parameters
r:float

the red component

g:float

the green component

b:float

the blue component

a:float

the alpha component

Exceptions
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
Colorback to summary
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:ColorSpace

the ColorSpace to be used to interpret the components

components:float[]

an arbitrary number of color components that is compatible with the ColorSpace

alpha:float

alpha value

Exceptions
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, getColorComponents

Method Detail

brighterback to summary
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:Color

a new Color object that is a brighter version of this Color with the same alpha value.

Since
1.0
See Also
java.awt.Color#darker
createContextback to summary
public PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints)

Implements java.awt.Paint.createContext.

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.

Parameters
cm:ColorModel

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:Rectangle

the device space bounding box of the graphics primitive being rendered.

r2d:Rectangle2D

the user space bounding box of the graphics primitive being rendered.

xform:AffineTransform

the AffineTransform from user space into device space.

hints:RenderingHints

the set of hints that the context object can use to choose between rendering alternatives.

Returns:PaintContext

the PaintContext for generating color patterns.

See Also
Paint, PaintContext, ColorModel, Rectangle, Rectangle2D, AffineTransform, RenderingHints
darkerback to summary
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:Color

a new Color object that is a darker version of this Color with the same alpha value.

Since
1.0
See Also
java.awt.Color#brighter
decodeback to summary
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:String

a String that represents an opaque color as a 24-bit integer

Returns:Color

the new Color object.

Exceptions
NumberFormatException:
if the specified string cannot be interpreted as a decimal, octal, or hexadecimal integer.
Since
1.1
See Also
java.lang.Integer#decode
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

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.

Parameters
obj:Object

the object to test for equality with this Color

Returns:boolean

true if the objects are the same; false otherwise.

Since
1.0
getAlphaback to summary
public int getAlpha()

Returns the alpha component in the range 0-255.

Returns:int

the alpha component.

See Also
getRGB
getBlueback to summary
public int getBlue()

Returns the blue component in the range 0-255 in the default sRGB space.

Returns:int

the blue component.

See Also
getRGB
getColorback 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 Color object.

If the specified property is not found or could not be parsed as an integer then null is returned.

Parameters
nm:String

the name of the color property

Returns:Color

the Color converted from the system property.

Since
1.0
See Also
java.lang.System#getProperty(java.lang.String), java.lang.Integer#getInteger(java.lang.String), java.awt.Color#Color(int)
getColorback 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 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.

Parameters
nm:String

the name of the color property

v:Color

the default Color

Returns:Color

the Color converted from the system property, or the specified Color.

Since
1.0
See Also
java.lang.System#getProperty(java.lang.String), java.lang.Integer#getInteger(java.lang.String), java.awt.Color#Color(int)
getColorback 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 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.

Parameters
nm:String

the name of the color property

v:int

the default color value, as an integer

Returns:Color

the Color converted from the system property or the Color converted from the specified integer.

Since
1.0
See Also
java.lang.System#getProperty(java.lang.String), java.lang.Integer#getInteger(java.lang.String), java.awt.Color#Color(int)
getColorComponentsback to summary
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:float[]

an array that this method fills with the color components of this Color in its ColorSpace and returns

Returns:float[]

the color components in a float array.

getColorComponentsback to summary
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:ColorSpace

a specified ColorSpace

compArray:float[]

an array that this method fills with the color components of this Color in the specified ColorSpace

Returns:float[]

the color components in a float array.

getColorSpaceback to summary
public ColorSpace getColorSpace()

Returns the ColorSpace of this Color.

Returns:ColorSpace

this Color object's ColorSpace.

getComponentsback to summary
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:float[]

an array that this method fills with the color and alpha components of this Color in its ColorSpace and returns

Returns:float[]

the color and alpha components in a float array.

getComponentsback to summary
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:ColorSpace

a specified ColorSpace

compArray:float[]

an array that this method fills with the color and alpha components of this Color in the specified ColorSpace and returns

Returns:float[]

the color and alpha components in a float array.

getGreenback to summary
public int getGreen()

Returns the green component in the range 0-255 in the default sRGB space.

Returns:int

the green component.

See Also
getRGB
getHSBColorback to summary
public static Color getHSBColor(float h, float s, float b)

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.

Parameters
h:float

the hue component

s:float

the saturation of the color

b:float

the brightness of the color

Returns:Color

a Color object with the specified hue, saturation, and brightness.

Since
1.0
getRedback to summary
public int getRed()

Returns the red component in the range 0-255 in the default sRGB space.

Returns:int

the red component.

See Also
getRGB
getRGBback to summary
public int getRGB()

Returns the RGB value representing the color in the default sRGB ColorModel, 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.
Returns:int

the RGB value of the color in the default sRGB ColorModel.

Since
1.0
See Also
java.awt.image.ColorModel#getRGBdefault, getRed, getGreen, getBlue
getRGBColorComponentsback to summary
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:float[]

an array that this method fills with color components and returns

Returns:float[]

the RGB components in a float array.

getRGBComponentsback to summary
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:float[]

an array that this method fills with color and alpha components and returns

Returns:float[]

the RGBA components in a float array.

getTransparencyback to summary
public int getTransparency()

Implements java.awt.Transparency.getTransparency.

Returns the transparency mode for this Color. This is required to implement the Paint interface.

Returns:int

this Color object's transparency mode.

See Also
Paint, Transparency, createContext
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Computes the hash code for this Color.

Returns:int

a hash code value for this object.

Since
1.0
HSBtoRGBback 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 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 getRGB. This integer can be supplied as an argument to the Color constructor that takes a single integer argument.

Parameters
hue:float

the hue component of the color

saturation:float

the saturation of the color

brightness:float

the brightness of the color

Returns:int

the RGB value of the color with the indicated hue, saturation, and brightness.

Since
1.0
See Also
java.awt.Color#getRGB(), java.awt.Color#Color(int), java.awt.image.ColorModel#getRGBdefault()
RGBtoHSBback 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 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:int

the red component of the color

g:int

the green component of the color

b:int

the blue component of the color

hsbvals:float[]

the array used to return the three HSB values, or null

Returns:float[]

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.

Since
1.0
See Also
java.awt.Color#getRGB(), java.awt.Color#Color(int), java.awt.image.ColorModel#getRGBdefault()
testColorValueRangeback to summary
private static void testColorValueRange(int r, int g, int b, int a)

Checks the color integer components supplied for validity. Throws an IllegalArgumentException if the value is out of range.

Parameters
r:int

the Red component

g:int

the Green component

b:int

the Blue component

testColorValueRangeback to summary
private static void testColorValueRange(float r, float g, float b, float a)

Checks the color float components supplied for validity. Throws an IllegalArgumentException if the value is out of range.

Parameters
r:float

the Red component

g:float

the Green component

b:float

the Blue component

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

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.

Returns:String

a string representation of this Color.