Java Color to HTML covertToHtmlColor(Color color)

Here you can find the source of covertToHtmlColor(Color color)

Description

covert To Html Color

License

Open Source License

Declaration

public static String covertToHtmlColor(Color color) 

Method Source Code


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

public class Main {
    public static String covertToHtmlColor(Color color) {
        return color == null ? null
                : "#" + to2BitHexString(color.getRed()) + to2BitHexString(color.getGreen())
                        + to2BitHexString(color.getBlue());
    }/*from w w  w .  j av a2  s . com*/

    private static String to2BitHexString(int i) {
        String ret = Integer.toHexString(i);
        if (ret.length() < 2) {
            ret = "0" + ret;
        }
        return ret;
    }
}

Related

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