Here you can find the source of toHexString(Color col)
Parameter | Description |
---|---|
Color | a parameter |
final public static String toHexString(Color col)
//package com.java2s; /* //from w ww . j a v a2s . c o m GeoGebra - Dynamic Mathematics for Everyone http://www.geogebra.org This file is part of GeoGebra. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. */ import java.awt.Color; public class Main { private static char[] hexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * converts Color to hex String with RGB values * @param Color * @return */ final public static String toHexString(Color col) { byte r = (byte) col.getRed(); byte g = (byte) col.getGreen(); byte b = (byte) col.getBlue(); StringBuffer sb = new StringBuffer(8); // RED sb.append(hexChar[(r & 0xf0) >>> 4]); // look up high nibble char sb.append(hexChar[r & 0x0f]); // look up low nibble char // GREEN sb.append(hexChar[(g & 0xf0) >>> 4]); // look up high nibble char sb.append(hexChar[g & 0x0f]); // look up low nibble char // BLUE sb.append(hexChar[(b & 0xf0) >>> 4]); // look up high nibble char sb.append(hexChar[b & 0x0f]); // look up low nibble char return sb.toString(); } }