0

I'm trying to convert FROM integer notation TO RGB notation.

"Integer notation is a value from 0 to 16777215 and it can be obtained from a rgb code rgb(R,G,B) using the formula 256*256*R+256*G+B."

I understand that, but what is the formula to convert from integer notation to RGB?

So if I enter 887766, I should get back (13,139,214) - how would I go about doing that?

Cheers guys

  • possible duplicate of [How to convert get.rgb(x,y) integer pixel to Color(r,g,b,a) in Java?](http://stackoverflow.com/questions/2534116/how-to-convert-get-rgbx-y-integer-pixel-to-colorr-g-b-a-in-java) – Jeroen Vannevel Oct 17 '13 at 02:39

3 Answers3

6

Take a look at java.awt.Color

Color color = new Color(intValue);
System.out.println(color.getRed() + ", " + color.getGreen() + ", " + color.getBlue());
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

Simple as: new Color(intValue)

SheetJS
  • 22,470
  • 12
  • 65
  • 75
James
  • 4,211
  • 1
  • 18
  • 34
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

user949300
  • 15,364
  • 7
  • 35
  • 66