[英]java : convert Hex color #RRGGBB to rgb r g b?
我的十六進制顏色字符串: #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 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.