简体   繁体   English

从Android Color对象获取红色,蓝色或绿色通道

[英]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.

相关问题 使用Color.brighter方法打印红色,绿色和蓝色值 - Using the Color.brighter method to print red, green, and blue values IllegalArgumentException:颜色参数超出预期范围:红色绿色蓝色 - IllegalArgumentException: Color parameter outside of expected range: Red Green Blue 使用适用于Android的OpenCV分别显示红色蓝色和绿色值 - Display the Red Blue and Green values separately using OpenCV for Android application 如何获得 colors 的五个输入的序列。 颜色应该只有红色,绿色和蓝色需要colors的图案。在Java中编程? - How to get a sequence of five inputs of colors. Color should be only Red,Green and Blue need a pattern of colors.Programming in Java? 将红色、绿色和蓝色转换为 RGB - Converting Red, Green and Blue to RGB Java - 红色,绿色,蓝色到getRGB - Java - Red, Green, Blue to getRGB Eclipse中的red(),green(),blue()方法 - red(), green(), blue() method in Eclipse BufferedImage交换红色和蓝色通道 - BufferedImage swap red and blue channel Java BufferedImage分别获得红色,绿色和蓝色 - Java BufferedImage getting red, green and blue individually 将色彩空间为8BitARGB的字节数组转换为BufferedImage时,哪个字节(Alpha,Red,Green,Blue)是错误的。TYPE_4BYTE_ABGR - Which byte(Alpha, Red, Green, Blue) is wrong when converting byte array with color space of 8BitARGB to BufferedImage.TYPE_4BYTE_ABGR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM