将RGB颜色值转换为十六进制 [英] Convert a RGB Color Value to a Hexadecimal

查看:205
本文介绍了将RGB颜色值转换为十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java应用程序中,我能够得到 JButton 颜色的值,红色,绿色,蓝色值;我已将这些值存储在三个整数中。

In my Java application, I was able to get the value of JButton color in terms of Red, Green, Blue values; I have stored these values in three integers.

如何将RGB值转换为等效的十六进制值?

How to convert RGB values into the equivalent hexadecimal value?

这种格式的例子#0033fA

推荐答案

String hex = String.format(#%02x%02x%02x,r,g,b); 使用大写X的,如果你想得到的十六进制数字大写(#FFFFFF vs. #ffffff)。

You can use String hex = String.format("#%02x%02x%02x", r, g, b); Use capital X's if you want your resulting hex-digits to be capitalized (#FFFFFF vs. #ffffff).

这篇关于将RGB颜色值转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆