Java RGB Color Convert To RGBtoHTML(int rgb)

Here you can find the source of RGBtoHTML(int rgb)

Description

Produces HTML color representation

License

Open Source License

Parameter

Parameter Description
rgb Integer color value

Return

HTML color representation

Declaration

public static String RGBtoHTML(int rgb) 

Method Source Code

//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();
    }
}

Related

  1. RGBtoHSV(int r, int g, int b, double hsv[])
  2. rgbToHsv(int red, int green, int blue)
  3. RGBtoHSV(int red, int green, int blue)
  4. RGBToHSV(int red, int green, int blue, float[] hsv)
  5. rgbToHsv(int rgb)
  6. RGBToInt(float[] rgb)
  7. RGBtoInt(int r, int g, int b)
  8. RGBtoInt(int red, int green, int blue)
  9. RGBtoInt(String rgb)