我尝试先将其转换为 RGB,然后将值除以 255,但结果不是我想要的。颜色比原来的更亮。
最佳答案
你尝试过Libgdx的Color类的函数valueOf()吗?
Color.valueOf(StringHex);//从十六进制字符串返回颜色
该函数执行以下操作,因为您没有发布任何代码,也许您可以发现是否出现问题:
/** Returns a new color from a hex string with the format RRGGBBAA.
* @see #toString() */
public static Color valueOf (String hex) {
hex = hex.charAt(0) == '#' ? hex.substring(1) : hex;
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);
int a = hex.length() != 8 ? 255 : Integer.valueOf(hex.substring(6, 8), 16);
return new Color(r / 255f, g / 255f, b / 255f, a / 255f);
}
关于libgdx - 如何将十六进制颜色值转换为libgdx颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52081247/