如何使用Java转换hex到rgb? [英] How to convert hex to rgb using Java?
本文介绍了如何使用Java转换hex到rgb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中将十六进制颜色转换为RGB代码?
How can I convert hex color to RGB code in Java? Mostly in Google, samples are on how to convert from RGB to hex.
推荐答案
我想这应该可以做到:
/**
*
* @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 ) );
}
这篇关于如何使用Java转换hex到rgb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文