Java Color to HTML colourToHtmlString(Color colour)

Here you can find the source of colourToHtmlString(Color colour)

Description

Converts a Color to an HTML String (#RRGGBB), ignoring transparency.

License

Open Source License

Parameter

Parameter Description
colour The colour to represent as a String

Return

The HTML representation of the , or null if a null was supplied.

Declaration

public static String colourToHtmlString(Color colour) 

Method Source Code


//package com.java2s;
import java.awt.Color;

public class Main {
    /**/*from w  ww.  ja v a  2s . c  o m*/
     * Converts a {@link Color} to an HTML {@link String} (#RRGGBB), ignoring
     * transparency.
     * 
     * @param colour
     *            The colour to represent as a {@link String}
     * @return The HTML representation of the {@link Color}, or
     *         <code>null</code> if a <code>null</code> {@link Color} was
     *         supplied.
     */
    public static String colourToHtmlString(Color colour) {
        if (colour == null) {
            return null;
        }
        return String.format("#%06X", colour.getRGB() & 0x00FFFFFF);
    }
}

Related

  1. attemptHTML(String colour)
  2. covertToHtmlColor(Color color)
  3. toHTMLColor(Color c)
  4. toHTMLColor(Color c)
  5. toHtmlColor(Color color)