如何从十六进制颜色code在java中的RGB值 [英] How to get RGB value from hexadecimal color code in java
本文介绍了如何从十六进制颜色code在java中的RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小数点颜色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;
这篇关于如何从十六进制颜色code在java中的RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文