Issue
How can I convert hex color to RGB code in Java? Mostly in Google, samples are on how to convert from RGB to hex.
Solution
I guess this should do it:
/**
*
* @param colorStr e.g. "#FFFFFF"
* @return
*/
public static Color hex2Rgb(String colorStr) {
return new Color(
Integer.valueOf( colorStr.substring( 1, 3 ), 16 ),
Integer.valueOf( colorStr.substring( 3, 5 ), 16 ),
Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) );
}
Answered By - xhh
Answer Checked By - Marie Seifert (JavaFixing Admin)