我正在尝试将整数表示法转换为 RGB 表示法。
“整数表示法是从 0 到 16777215 的值,可以使用公式 256*256*R+256*G+B 从 rgb 代码 rgb(R,G,B) 获得。”
我明白,但是从整数表示法转换为 RGB 的公式是什么?
所以如果我输入 887766,我应该返回 (13,139,214) - 我该怎么做呢?
干杯伙计们
Color color = new Color(intValue);
System.out.println(color.getRed() + ", " + color.getGreen() + ", " + color.getBlue());
If you mean "how can I convert the integer to something a human can look at to understand the R,G,B values", you could convert to hexadecimal. Assuming you understand hex. For example, red is ff0000.
See Integer.toHexString()
You may wish to add a leading "0x" for clarity.
If you literally mean how do I get 3 rgb values as 0-255, check out the link @Jeroen provided
简单如:new Color(intValue)