Java Utililty Methods Color to Hex

List of utility methods to do Color to Hex

Description

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

Method

StringtoHexString(Color color)
to Hex String
String hexaWith8Digits = Integer.toHexString(color.getRGB());
return new StringBuilder("#").append(hexaWith8Digits.substring(2, hexaWith8Digits.length())).toString();
StringtoHexString(final Color aColor)
Returns the given color instance as a string in the form of RR GG BB in which RR, GG, BB are the hexadecimal representations of red, green and blue.
final StringBuilder sb = new StringBuilder();
sb.append(String.format("%02x", Integer.valueOf(aColor.getRed())));
sb.append(String.format("%02x", Integer.valueOf(aColor.getGreen())));
sb.append(String.format("%02x", Integer.valueOf(aColor.getBlue())));
return sb.toString();
StringtoHexString(java.awt.Color c)
Convert the given color to is string hex representation
return "#" + padRight(Integer.toHexString(c.getRed()), 2, "0")
        + padRight(Integer.toHexString(c.getGreen()), 2, "0")
        + padRight(Integer.toHexString(c.getBlue()), 2, "0");
StringtoHexString(java.awt.Color c)
to Hex String
return toHexString(c.getRGB());
StringtoHexString(java.awt.Color colour)
to Hex String
String hexColour = Integer.toHexString(colour.getRGB() & 0xffffff);
if (hexColour.length() < 6) {
    hexColour = "000000".substring(0, 6 - hexColour.length()) + hexColour;
return "#" + hexColour;