Here you can find the source of encode(Color color)
Parameter | Description |
---|---|
color | The color that is encoded. |
public static String encode(Color color)
//package com.java2s; //License from project: Open Source License import java.awt.Color; public class Main { private static final int MAX_RGB_VALUE = 255; /**//from www . java2s . co m * Encodes the specified color to a hexadecimal string representation. * The output format is: * <ul> * <li>#RRGGBB - For colors without alpha</li> * <li>#AARRGGBB - For colors with alpha</li> * </ul> * Examples: <br> * <code>Color.RED</code> = "#ff0000"<br> * <code>new Color(255, 0, 0, 200)</code> = "#c8ff0000" * * @param color * The color that is encoded. * @return An hexadecimal string representation of the specified color. * * @see ColorHelper#decode(String) * @see Color * @see Color#getRGB() * @see Integer#toHexString(int) */ public static String encode(Color color) { if (color == null) { return null; } if (color.getAlpha() == MAX_RGB_VALUE) { return "#" + Integer.toHexString(color.getRGB()).substring(2); } else { return "#" + Integer.toHexString(color.getRGB()); } } }