简体   繁体   English

如何使用 Java 在 Android 中获取颜色的 R、G、B 值?

[英]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 :我需要调整一些颜色的 R、G、B 值,所以我将它传递给一个方法并尝试返回调整后的值:

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;
  }

If I understand it correctly you need to extract the color values from the itemColor variable.如果我理解正确,您需要从itemColor变量中提取颜色值。 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;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM