Here you can find the source of RGBtoHTML(int rgb)
Parameter | Description |
---|---|
rgb | Integer color value |
public static String RGBtoHTML(int rgb)
//package com.java2s; public class Main { /**//ww w . j av a 2s. co m * Produces HTML color representation * * @param rgb Integer color value * @return HTML color representation */ public static String RGBtoHTML(int rgb) { final StringBuilder b = new StringBuilder("0000000"); b.replace(0, 1, "#"); for (int i = 5; i > 0; i -= 2) { final int bt = rgb & 0xFF; rgb = rgb >> 8; StringBuilder b2 = new StringBuilder(Integer.toString(bt, 16)); if (bt < 16) { b2.insert(0, "0"); } b.replace(i, i + 2, b2.toString()); } return b.toString(); } }