java : convert Hex color #RRGGBB to rgb r g b?

标签 java colors

我的十六进制颜色字符串:#ffffff

我想要简单的方法将字符串#rrggbb转换为int r; int g; int b;

int color = (int)Long.parseLong(myHexColor, 16);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;

这个方法是真的吗?

谢谢。

编辑:______________________________

String colorStr = "#ffffff";
int  r=  Integer.valueOf( colorStr.substring( 1, 3 ), 16 );
int  g=  Integer.valueOf( colorStr.substring( 3, 5 ), 16 );
int  b=  Integer.valueOf( colorStr.substring( 5, 7 ), 16 );

最佳答案

你可以尝试:

    int  r=  Integer.valueOf( colorStr.substring( 1, 3 ), 16 );
    int  g=  Integer.valueOf( colorStr.substring( 3, 5 ), 16 );
    int  b=  Integer.valueOf( colorStr.substring( 5, 7 ), 16 );

关于java : convert Hex color #RRGGBB to rgb r g b?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31227036/

相关文章:

swift - 我是 Xcode 新手,我正在尝试更改项目的背景颜色

java - 在运行时为 JTable 的特定行设置背景颜色

java - 如何访问 Netbeans 7.4 中的系统颜色?

java - Swing 在作业运行时更新 UI 组件

java - Mule MUnit FTP 服务器架构定义

java - 尝试使用 Java 代理运行 WebGoat 时崩溃

c++ - 更改 MFC 列表控件标题颜色

java - iText 单元格边框穿过文本

java - Java 如何知道在此示例中使用哪个类?

c# - 带颜色的开关/外壳