Convert a RGB Color Value to a Hexadecimal String
问题 In my Java application, I was able to get the Color of a JButton in terms of red, green and blue; I have stored these values in three int s. How do I convert those RGB values into a String containing the equivalent hexadecimal value? An Example would be "#0033fA" 回答1: 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 ). 回答2: A one liner but without String.format: Color your_color =