MCPcopy Create free account
hub / github.com/VolmitSoftware/Adapt / hexToColor

Method hexToColor

src/main/java/com/volmit/adapt/util/C.java:412–431  ·  view source on GitHub ↗
(String hex)

Source from the content-addressed store, hash-verified

410 }
411
412 public static Color hexToColor(String hex) {
413 if (hex.startsWith("#")) {
414 hex = hex.substring(1);
415 }
416
417 if (hex.indexOf("x") != -1) {
418 hex = hex.substring(hex.indexOf("x"));
419 }
420
421 if (hex.length() != 6 && hex.length() != 3) {
422 return null;
423 }
424 int sz = hex.length() / 3, mult = 1 << ((2 - sz) * 4), x = 0;
425
426 for (int i = 0, z = 0; z < hex.length(); ++i, z += sz) {
427 x |= (mult * Integer.parseInt(hex.substring(z, z + sz), 16)) << (i * 8);
428 }
429
430 return Color.fromBGR(x & 0xffffff);
431 }
432
433 public static Color rgbToColor(String rgb) {
434 String[] parts = rgb.split("[^0-9]+");

Callers

nothing calls this directly

Calls 1

lengthMethod · 0.45

Tested by

no test coverage detected