简体   繁体   English

java:将十六进制颜色#RRGGBB 转换为 rgb rgb?

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

my hex color string : #ffffff我的十六进制颜色字符串: #ffffff

i want simple way to convert string #rrggbb to int r;我想要简单的方法将字符串#rrggbbint 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;

this method is true?这个方法是真的吗?

thanks.谢谢。

Edit:______________________________编辑:______________________________

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 );

You can try:你可以试试:

    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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM