Java Color to Hex toHex(Color color)

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

Description

Returns a hex string for the given color in RGB format.

License

Open Source License

Parameter

Parameter Description
color the color

Return

String

Declaration

public static final String toHex(Color color) 

Method Source Code


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

public class Main {
    /**//ww w . j av  a  2  s  . co m
     * Returns a hex string for the given color in RGB format.
     * <p>
     * Transparency is ignored.
     * @param color the color
     * @return String
     */
    public static final String toHex(Color color) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();
        return String.format("%02x", r) + String.format("%02x", g) + String.format("%02x", b);
    }
}

Related

  1. toHex(Color c)
  2. toHex(Color color)
  3. toHex(Color color)
  4. toHex(Color color)
  5. toHex(Color color)
  6. toHex(Color color)
  7. toHex(java.awt.Color color)
  8. toHex0x(Color col)
  9. toHexCode(String prefix, Color color)