returns a hexadecimal string representation of the color - eg "AABBCC" or "DDAABBCC" The DD in this case gives the opacity value - Java 2D Graphics

Java examples for 2D Graphics:Color String

Description

returns a hexadecimal string representation of the color - eg "AABBCC" or "DDAABBCC" The DD in this case gives the opacity value

Demo Code

/** Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT  */
//package com.java2s;
import java.awt.*;

public class Main {
    /**//w w w .  j av  a 2  s.  c  om
     * returns a hexadecimal string representation of the color - eg "AABBCC" or "DDAABBCC"
     * The DD in this case gives the opacity value
     * @return html color
     */
    public static String getHTMLColorFromColor(Color color) {
        int intval = color.getRGB();
        intval -= 0xFF000000;
        //System.out.println("NodePres getString from PathColor = "+Integer.toHexString(intval).toUpperCase());
        return '#' + Integer.toHexString(intval).toUpperCase();
    }
}

Related Tutorials