Frank
Frank

Reputation: 31086

How to get R,G,B values of a color in Android with Java?

I need to adjust the R,G,B values of some color, so I pass it to a method and try to return the adjusted value :

itemColor == Color.rgb(28,158,218);

...

  int adjustColor(int itemColor)
  {
     int adjustedColor;

     //How to get the R,G,B of the itemColor here ?

     adjustedColor = Color.rgb(R/2,G/2,B/2);
     return adjustedColor;
  }

Upvotes: 0

Views: 809

Answers (1)

davidm
davidm

Reputation: 1750

If I understand it correctly you need to extract the color values from the itemColor variable. So use the following method:

int adjustColor(int itemColor)
  {
     int adjustedColor;

     int R = Color.red(itemColor);
     int B = Color.blue(itemColor);
     int G = Color.green(itemColor);

     adjustedColor = Color.rgb(R/2,G/2,B/2);
     return adjustedColor;
  }

Upvotes: 2

Related Questions