Java Color to Hex toHexString(java.awt.Color c)

Here you can find the source of toHexString(java.awt.Color c)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(java.awt.Color c) 

Method Source Code

//package com.java2s;
/*// w w w  .  jav  a2  s .c o  m
 * $Id$
 * (c) Copyright 2000 wingS development team.
 *
 * This file is part of wingS (http://j-wings.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */

public class Main {
    final static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f' };

    public static String toHexString(int rgb) {
        char[] buf = new char[6];
        int digits = 6;
        do {
            buf[--digits] = hexDigits[rgb & 15];
            rgb >>>= 4;
        } while (digits != 0);

        return new String(buf);
    }

    public static String toHexString(java.awt.Color c) {
        return toHexString(c.getRGB());
    }
}

Related

  1. toHexString(Color color)
  2. toHexString(Color color)
  3. toHexString(Color color)
  4. toHexString(final Color aColor)
  5. toHexString(java.awt.Color c)
  6. toHexString(java.awt.Color colour)