Java RGB Color Create toRgbText(int rgb)

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

Description

Convert an integer to an HTML RGB value.

License

Open Source License

Parameter

Parameter Description
rgb the integer RGB value

Return

the value as an HTML RGB string

Declaration


public static String toRgbText(int rgb) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  www.j av a  2s  . c  o m*/
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Convert an integer to an HTML RGB value. The result is of the form
     * #hhhhhh. The input rgb integer value will be clipped into the range 0 ~
     * 0xFFFFFF
     * 
     * @param rgb
     *            the integer RGB value
     * @return the value as an HTML RGB string
     */

    public static String toRgbText(int rgb) {
        // clip input value.

        if (rgb > 0xFFFFFF)
            rgb = 0xFFFFFF;
        if (rgb < 0)
            rgb = 0;

        String str = "000000" + Integer.toHexString(rgb); //$NON-NLS-1$ 
        return "#" + str.substring(str.length() - 6); //$NON-NLS-1$ 
    }
}

Related

  1. toRGBA(int argb)
  2. toRGBA(int color)
  3. toRGBA(String hexARGB)
  4. toRGBAArray(int colorBuffer)
  5. toRGBAIntArray(long argb)