List of utility methods to do Color Create
Paint | generateTexturePaint(String text, Font font, Color textColor, Color bgColor, int width, int height) Generates a TexturePaint of the given size, using the given text as a pattern. BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bi.createGraphics();
g2.setColor(bgColor);
g2.fillRect(0, 0, width, height);
g2.setColor(textColor);
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
g2.drawString(text, (width - fm.stringWidth(text)) / 2,
...
|
Color[] | generateVisuallyDistinctColors(int ncolors, float minComponent, float maxComponent) Returns an array of ncolors RGB triplets such that each is as unique from the rest as possible and each color has at least one component greater than minComponent and one less than maxComponent. rand.setSeed(RAND_SEED); float[][] yuv = new float[ncolors][3]; for (int got = 0; got < ncolors;) { System.arraycopy(randYUVinRGBRange(minComponent, maxComponent), 0, yuv[got++], 0, 3); for (int c = 0; c < ncolors * 1000; c++) { float worst = 8888; int worstID = 0; ... |
Color | toColor(byte red, byte green, byte blue) Convert RGB color model to a Color object return new Color(red, green, blue); |
Color | toColor(byte[] bytes) to Color return new Color((int) bytes[0], (int) bytes[1], (int) bytes[2], (int) bytes[3]); |
Color | toColor(final String hexColor) Converts hex color representation to java.awt.Color object. Color color = null; if (hexColor.length() == ALPHA_END_INDEX) { final String red = hexColor.substring(RED_BEGIN_INDEX, RED_END_INDEX); final String green = hexColor.substring(GREEN_BEGIN_INDEX, GREEN_END_INDEX); final String blue = hexColor.substring(BLUE_BEGIN_INDEX, BLUE_END_INDEX); final String alpha = hexColor.substring(ALPHA_BEGIN_INDEX, ALPHA_END_INDEX); color = new Color(Integer.parseInt(red, HEX_RADIX), Integer.parseInt(green, HEX_RADIX), Integer.parseInt(blue, HEX_RADIX), Integer.parseInt(alpha, HEX_RADIX)); ... |
Color | toColor(final String hexString) In a lot of HTML documents and still others, colors are represented using the RGB values, concatenated as hexadecimal strings. return new Color(Character.digit(hexString.charAt(1), 16) * 16 + Character.digit(hexString.charAt(2), 16), Character.digit(hexString.charAt(3), 16) * 16 + Character.digit(hexString.charAt(4), 16), Character.digit(hexString.charAt(5), 16) * 16 + Character.digit(hexString.charAt(6), 16)); |
Color | toColor(final String text, final Color defaultValue) Re-conversion of the human readable RGB representation back to a Color :
if ("none".equals(text)) { return null; if (text != null) { final String[] colorValues = text.replaceAll("[^0-9]+", " ").trim().split(" "); if (colorValues.length == 3) { final int red = Integer.valueOf(colorValues[0]).intValue(); final int green = Integer.valueOf(colorValues[1]).intValue(); ... |
Color | toColor(float[] color) to Color if (color.length == 4) return new Color(color[0], color[1], color[2], color[3]); else return new Color(color[0], color[1], color[2], 1); |
Color | toColor(int rgba) to Color int r = rgba & 0xFF, g = rgba >> 8 & 0xFF, b = rgba >> 16 & 0xFF, a = rgba >> 24 & 0xFF; return new Color(r, g, b, a); |
Color | toColor(int x) Converts an ARGB int to a Color. return new Color(x, true); |