如何从JavaFX ColorPicker颜色获取十六进制web字符串? [英] How to get hex web String from JavaFX ColorPicker color?
本文介绍了如何从JavaFX ColorPicker颜色获取十六进制web字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JavaFX ColorPicker中选择了Color。现在我需要将其保存为十六进制字符串。我发现这个方法,但对于JavaFX它不适用。 JavaFX有自己的Color类没有getRGB()方法,可以用作中介转换。
I have Color chosen in JavaFX ColorPicker. Now I need to save it as hex string. I found this method, but for JavaFX it is not applicable. JavaFX has its own Color class without getRGB() method, that could be used as mediatory convertion.
推荐答案
// 8 symbols.
String hex1 = Integer.toHexString(myColorPicker.getValue().hashCode());
// With # prefix.
String hex2 = "#" + Integer.toHexString(myColorPicker.getValue().hashCode());
// 6 symbols in capital letters.
String hex3 = Integer.toHexString(myColorPicker.getValue().hashCode()).substring(0, 6).toUpperCase();
这篇关于如何从JavaFX ColorPicker颜色获取十六进制web字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文