0

我正在尝试将整数表示法转换为 RGB 表示法。

“整数表示法是从 0 到 16777215 的值,可以使用公式 256*256*R+256*G+B 从 rgb 代码 rgb(R,G,B) 获得。”

我明白,但是从整数表示法转换为 RGB 的公式是什么?

所以如果我输入 887766,我应该返回 (13,139,214) - 我该怎么做呢?

干杯伙计们

4

3 回答 3

6

看一眼java.awt.Color

Color color = new Color(intValue);
System.out.println(color.getRed() + ", " + color.getGreen() + ", " + color.getBlue());
于 2013-10-17T02:37:29.767 回答
0

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

于 2013-10-17T02:47:32.610 回答
0

简单如:new Color(intValue)

于 2013-10-17T02:39:24.040 回答