List of utility methods to do Hex to Color
Color | hexToColor(final String hex) Gets the corresponding Color object for this hexidecimal string. if (hex == null) return null; final int len = hex.length(); if (len == 0 || len % 3 != 0) return null; final int len3 = len / 3; final float max = (float) Math.pow(16, len3) - 1; Color color = null; ... |
Color | hexToColor(String color) Convert html hex string to Color. try { if (color.charAt(0) == '#') { color = color.substring(1, 7); int[] col = new int[3]; for (int i = 0; i < 3; i++) { col[i] = Integer.parseInt(color.substring(i * 2, (i * 2) + 2), 16); return new Color(col[0], col[1], col[2]); } catch (Exception e) { return Color.black; |
Color | hexToColor(String color) Convert html hex string to Color. try { if (color.charAt(0) == '#') { color = color.substring(1, 7); int[] col = new int[3]; for (int i = 0; i < 3; i++) { col[i] = Integer.parseInt(color.substring(i * 2, (i * 2) + 2), 16); return new Color(col[0], col[1], col[2]); } catch (Exception e) { return Color.black; |
Color | hexToColor(String colorHex) Hex to color. final String replace = colorHex.replace("#", "0x"); return Color.decode(replace); |
Color | hexToColor(String hex) hex To Color hex = hex.replace("#", ""); if (hex.length() == 6) { int r = Integer.valueOf(hex.substring(0, 2), 16); int g = Integer.valueOf(hex.substring(2, 4), 16); int b = Integer.valueOf(hex.substring(4, 6), 16); return new Color(r, g, b); return Color.BLACK; ... |
boolean | hexToColor(String hexStr, boolean throwException, int[] buffer) hex To Color int type = checkHexString(hexStr, throwException); if (type < 0) return (false); int start = ((type & 1) != 0) ? 1 : 0; if (((type & 2) != 0) && buffer.length < 4) { if (throwException) throw new IllegalArgumentException("buffer too small"); return (false); ... |
Color | hexToColor(String hexString) hex To Color return Color.decode(hexString);
|
Color | hexToColor(String hexString) Convert a hex string to a color object int decimalColor; decimalColor = Integer.parseInt(hexString, 16); return new Color(decimalColor); |
Color | hexToColor(String input) hex To Color String hex = input; if (hex.startsWith("#")) { hex = hex.substring(1); Matcher matcher = pattern.matcher(hex); if (matcher.matches()) { if (hex.length() == 1) { int value = Integer.parseInt(hex, 16); ... |
Color | hexToColor(String s) Convert Hex String to Color. String clr = s.substring(1); if (clr.length() == 3) { clr = new String(new char[] { clr.charAt(0), clr.charAt(0), clr.charAt(1), clr.charAt(1), clr.charAt(2), clr.charAt(2) }); if (clr.length() != 6) throw new IllegalArgumentException(); return new Color(Integer.parseInt(clr, 16)); ... |