如何从十六进制颜色code在java中的RGB值颜色、十六进制、code、RGB

2023-09-13 23:56:06 作者:白天卟懂爷旳黒

我有一个小数点颜色code(例如: 4898901 )。我把它转换成一个十六进制值作为 4ac055 。如何从十六进制颜色code得到红色,绿色和蓝色成分值?

I have a decimal color code (eg: 4898901). I am converting it into a hexadecimal equivalent of that as 4ac055. How to get the red, green and blue component value from the hexadecimal color code?

推荐答案

假设这是一个字符串:

// edited to support big numbers bigger than 0x80000000
int color = (int)Long.parseLong(myColorString, 16);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;