[英]Get Red, Blue or Green channel from Android Color object
I feel this is a pretty stupid question, but the Android Color class doesn't seem to have a method to get an int from the R, G, B channels from a Color object individually. 我觉得这是一个非常愚蠢的问题,但Android Color类似乎没有一种方法可以从Color对象中单独从R,G,B通道获取int。 Can I get the channels somehow like java.awt's Color can? 我能不能像java.awt的颜色那样得到频道?
int color = ContextCompat.getColor(context, R.color.someColor);
int red = Color.red(color);
int blue = Color.blue(color);
int green = Color.green(color);
int alpha = Color.alpha(color);
Did you mean 你的意思是
int colorValue=Color.parseColor(#121212);
int red=Color.red(colorValue);
int green=Color.green(colorValue);
int blue=Color.blue(colorValue);
try this: 尝试这个:
String myPassedColor = "#ffffff";
int color = Color.parseColor(myPassedColor)
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
int a = Color.alpha(color);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.