How to get RGB value from hexadecimal color code i

2020-01-31 03:33发布

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?

7条回答
Bombasti
2楼-- · 2020-01-31 04:02

Try this,

colorStr e.g. "#FFFFFF"

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

For using Color class you have to use java-rt-jar-stubs-1.5.0.jar as Color class is from java.awt.Color

查看更多
登录 后发表回答