Java Utililty Methods Color Encode

List of utility methods to do Color Encode

Description

The list of methods to do Color Encode are organized into topic(s).

Method

StringencodeColorForCss(Color color)
encode Color For Css
if (null == color) {
    return "#000000";
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()).toUpperCase();
StringencodeRGB(Color color)
Encode to the color data type, see section 18.3.8 of OpenDocument-v1.2-part1.
return "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase();
StringencodeRGBHexString(Color color, boolean withAlpha)
Create a string representation of the color in the format #RRGGBB or #RRGGBBAA if withAlpha is true.
if (color == null) {
    return null;
StringBuilder colorString = new StringBuilder(withAlpha ? 9 : 7);
colorString.append("#");
appendHexString(colorString, color.getRed());
appendHexString(colorString, color.getGreen());
appendHexString(colorString, color.getBlue());
...
StringencodeRGBIntString(Color color, boolean withAlpha)
Create a string of the integer values of the RGB components of the color.
if (color == null) {
    return null;
StringBuilder colorString = new StringBuilder();
colorString.append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue());
if (withAlpha) {
    colorString.append(",").append(color.getAlpha());
return colorString.toString();