Java color get hex

Class Color

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 .

Field Summary

Fields declared in interface java.awt.Transparency

Constructor Summary

Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 — 1.0).

Читайте также:  Handle image in javascript

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 — 1.0).

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 a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Method Summary

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

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

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.

Methods declared in class java.lang.Object

Field Details

white

WHITE

lightGray

LIGHT_GRAY

gray

GRAY

darkGray

DARK_GRAY

black

BLACK

red

RED

pink

PINK

orange

ORANGE

yellow

YELLOW

green

GREEN

magenta

MAGENTA

cyan

CYAN

blue

BLUE

Constructor Details

Color

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.

Color

Color

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.

Color

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.

Color

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.

Color

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

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.

Method Details

getRed

getGreen

getBlue

getAlpha

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

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.

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.

hashCode

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.

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 .

decode

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.

getColor

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.

getColor

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.

getColor

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.

HSBtoRGB

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.

RGBtoHSB

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.

getHSBColor

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.

getRGBComponents

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.

getRGBColorComponents

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.

getComponents

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.

getColorComponents

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.

getComponents

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.

getColorComponents

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.

getColorSpace

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.

getTransparency

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Оцените статью