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

StringtoHexColor(Color col)
to Hex Color
StringBuffer res = new StringBuffer();
res.append("#");
String val = Long.toHexString((long) col.getRGB() & 0xFFFFFF);
for (int i = 0; i < (6 - val.length()); i++)
    res.append("0");
res.append(val);
return res.toString();
StringtoHexColor(Color col)
to Hex Color
return Integer.toHexString((col.getRGB() & 0xffffff) | 0x1000000).substring(1);
StringtoHexColor(final Color color)
Converts java.awt.Color object to hex string.
final String red = pad(Integer.toHexString(color.getRed()));
final String green = pad(Integer.toHexString(color.getGreen()));
final String blue = pad(Integer.toHexString(color.getBlue()));
final String alpha = pad(Integer.toHexString(color.getAlpha()));
return red + green + blue + alpha;
StringtoHexColor(final Color color)
Converts a given color to it's hexidecimal equivalent.
return "#" + colorToHexCode(color);
StringtoHexString(Color c)
Converts a color to its hexadecimal string representation for VzText e.g.
String r = Integer.toHexString(c.getRed());
String g = Integer.toHexString(c.getGreen());
String b = Integer.toHexString(c.getBlue());
String a = Integer.toHexString(c.getAlpha());
if (r.length() == 1)
    r = "0" + r;
if (g.length() == 1)
    g = "0" + g;
...
StringtoHexString(Color col)
converts Color to hex String with RGB values
byte r = (byte) col.getRed();
byte g = (byte) col.getGreen();
byte b = (byte) col.getBlue();
StringBuffer sb = new StringBuffer(8);
sb.append(hexChar[(r & 0xf0) >>> 4]);
sb.append(hexChar[r & 0x0f]); 
sb.append(hexChar[(g & 0xf0) >>> 4]);
sb.append(hexChar[g & 0x0f]); 
...
StringtoHexString(Color col)
converts Color to hex String with RGB values
byte r = (byte) col.getRed();
byte g = (byte) col.getGreen();
byte b = (byte) col.getBlue();
if (hexSB == null)
    hexSB = new StringBuilder(8);
else
    hexSB.setLength(0);
hexSB.append(hexChar[(r & 0xf0) >>> 4]);
...
StringtoHexString(Color color)
to Hex String
return String.format("#%06x", (color.getRGB() & 0x00ffffff));
StringtoHexString(Color color)
Produces a String representing the passed in color as a hex value (including the #) suitable for use in html.
return "#" + ("" + Integer.toHexString(color.getRGB())).substring(2);
StringtoHexString(Color color)
Converts a color to its hex representation (0xFFFFFF).
if (color == null) {
    return null;
StringBuilder str = new StringBuilder("0x");
if (color.getRed() < 16) {
    str.append('0');
str.append(Integer.toHexString(color.getRed()));
...