Java Color to Hex toHex(Color color)

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

Description

to Hex

License

Open Source License

Declaration

public static String toHex(Color color) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

public class Main {
    public static String toHex(Color color) {
        String alpha = pad(Integer.toHexString(color.getAlpha()));
        String red = pad(Integer.toHexString(color.getRed()));
        String green = pad(Integer.toHexString(color.getGreen()));
        String blue = pad(Integer.toHexString(color.getBlue()));
        return "#" + red + green + blue + alpha;
        //return Integer.parseInt(hex, 16);
    }/*from   w  ww  .jav  a  2  s . co m*/

    private static String pad(String s) {
        return (s.length() == 1) ? "0" + s : s;
    }
}

Related

  1. toHex(Color c)
  2. toHex(Color color)
  3. toHex(Color color)
  4. toHex(Color color)
  5. toHex(Color color)