Here you can find the source of toHexString(Color c)
Parameter | Description |
---|---|
Color | a parameter |
public static String toHexString(Color c)
//package com.java2s; //License from project: LGPL import java.awt.*; public class Main { /**//w w w . ja v a 2 s.co m * Converts a color to its hexadecimal string representation for VzText * e.g. #AARRGGBB * @param Color */ public static String toHexString(Color c) { // Either one or two characters long 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; if (b.length() == 1) b = "0" + b; if (a.length() == 1) a = "0" + a; return "#" + a + r + g + b; } /** * Converts a color to its hexadecimal string representation for VzText and * e.g. #AARRGGBB * @param int color in aarrggbb format (as from getRGB()) */ public static String toHexString(int color) { // Either one or two characters long String r = Integer.toHexString((color >> 16) & 0xFF); String g = Integer.toHexString((color >> 8) & 0xFF); String b = Integer.toHexString((color >> 0) & 0xFF); String a = Integer.toHexString((color >> 24) & 0xFF); if (r.length() == 1) r = "0" + r; if (g.length() == 1) g = "0" + g; if (b.length() == 1) b = "0" + b; if (a.length() == 1) a = "0" + a; return "#" + a + r + g + b; } }