Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

In this page you can find the example usage for java.awt Color getRGB.

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:de.unidue.inf.is.ezdl.gframedl.utils.HighlightingUtils.java

/**
 * Coverts a {@link Color} to a hex value for HTML.
 * //from w w  w  . java 2  s.  co m
 * @param color
 *            The {@link Color} to convert
 * @return The hex value for HTML
 */
public static String colorToHex(Color color) {
    return "#" + Integer.toHexString(color.getRGB() & 0x00ffffff);
}

From source file:Transparency.java

public static Image makeColorTransparent(Image im, final Color color) {
    ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque
        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override//from ww  w  .  j  a  v a  2s .  com
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:gate.termraider.output.CloudGenerator.java

private static String getHTMLColor(Color color) {
    return "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase();
}

From source file:se.trixon.almond.GraphicsHelper.java

public static String colorToHex(Color color) {
    String rgb = Integer.toHexString(color.getRGB());

    return rgb.substring(2);
}

From source file:HtmlColor.java

public static String encodeRGB(Color color) {
    if (null == color) {
        throw new IllegalArgumentException("NULL_COLOR_PARAMETER_ERROR_2");
    }/*from  w ww  .  j av a 2  s .  c  o m*/
    return "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase();
}

From source file:cl.almejo.vsim.gui.ColorScheme.java

public static String save() throws IOException {
    HashMap<String, HashMap<String, String>> map = new HashMap<String, HashMap<String, String>>();
    for (String schemeName : _schemes.keySet()) {
        ColorScheme scheme = _schemes.get(schemeName);
        HashMap<String, String> colors = new HashMap<String, String>();
        for (String colorName : scheme._colors.keySet()) {
            Color color = scheme._colors.get(colorName);
            colors.put(colorName, "#" + Integer.toHexString(color.getRGB()).substring(2));
        }//www  . j a  v  a2s  . c o  m
        map.put(schemeName, colors);
    }
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
}

From source file:gov.nih.nci.caintegrator.ui.graphing.legend.LegendCreator.java

/**
 * converts an awt.Color to a hex color string
 * in the format: #zzzzzz for use in HTML
 * @param c//w w  w.  java  2 s.c  om
 * @return
 */
public static String c2hex(Color c) {
    //http://rsb.info.nih.gov/ij/developer/source/index.html
    final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    int i = c.getRGB();
    char[] buf7 = new char[7];
    buf7[0] = '#';
    for (int pos = 6; pos >= 1; pos--) {
        buf7[pos] = hexDigits[i & 0xf];
        i >>>= 4;
    }
    return new String(buf7);
}

From source file:Main.java

/**
 * Creates a static rectangular image with given color, width and height.
 *//*from   w  ww.j  a va  2  s .c  o  m*/
public static Icon buildStaticImage(Color color, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            image.setRGB(x, y, color.getRGB());
        }
    }
    return new ImageIcon(image);
}

From source file:org.yccheok.jstock.chat.Utils.java

private static String toCSSHTML(Color color) {
    return Integer.toHexString(color.getRGB() & 0x00ffffff);
}

From source file:Main.java

public static BufferedImage getTransparentImage(BufferedImage image, Color transparent) {
    BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            if (image.getRGB(x, y) != transparent.getRGB()) {
                img.setRGB(x, y, image.getRGB(x, y));
            }//  w w w  .j a  v a 2s. c o  m
        }
    }
    g.dispose();
    return img;
}