Return the given color to hex code. - Java 2D Graphics

Java examples for 2D Graphics:Color HEX

Description

Return the given color to hex code.

Demo Code


//package com.java2s;
import javafx.scene.paint.Color;

public class Main {
    /**/*from w w  w . ja  v  a  2 s  .  c o m*/
     * Return the given color to hex code.
     * E.g. Color white is #FFFFFF.
     * 
     * @param color
     * @return hex color String
     */
    public static String getRGBCode(Color color) {
        return String.format("#%02X%02X%02X", (int) (color.getRed() * 255),
                (int) (color.getGreen() * 255),
                (int) (color.getBlue() * 255));
    }
}

Related Tutorials