Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

Returns the green component in the range 0-255 in the default sRGB space.

Usage

From source file:JavaTron.JTP.java

/**
 * Parses a Color type to a CSV type RGB string
 * @param c A Color Object//from  ww  w . ja  v a2 s  .  c o m
 * @return A String in the form of R,G,B i.e '0,255,127'
 */
public static String parseColor(Color c) {
    int red = c.getRed();
    int green = c.getGreen();
    int blue = c.getBlue();
    String csv = Integer.toString(red) + "," + Integer.toString(green) + "," + Integer.toString(blue);
    return csv;
}

From source file:org.polymap.rhei.batik.engine.svg.Svg2PngTask.java

static RGB getTypedRGB(String rgbStr) {
    if (rgbStr == null) {
        return null;
    }//from www . j  a v a 2  s. c  om
    if (rgbStr.startsWith("#")) {
        rgbStr = rgbStr.substring(1);
    }
    if (!rgbStr.startsWith("0x")) {
        rgbStr = "0x" + rgbStr;
    }
    Color color = Color.decode(rgbStr);
    return new RGB(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:ColorUtils.java

/**
 * Serializes a color to its HTML markup (e.g. "#ff0000" for red)
 * //from   w  w  w  .j a  v a2  s.c o  m
 * @param c The color to serialize
 * @return The HTML markup of the color
 */
public static String toHTML(Color c) {
    String ret = "#";
    String hex;
    hex = Integer.toHexString(c.getRed());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    hex = Integer.toHexString(c.getGreen());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    hex = Integer.toHexString(c.getBlue());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    return ret;
}

From source file:Main.java

public static Color getGradientRgbColor(float ratio, Color minColor, Color maxColor) {
    if (ratio < 0)
        ratio = 0.0F;//from   w w w . ja va2s. com
    if (ratio > 1.0)
        ratio = 1.0F;
    int red = (int) (maxColor.getRed() * ratio + minColor.getRed() * (1.0 - ratio));
    int green = (int) (maxColor.getGreen() * ratio + minColor.getGreen() * (1 - ratio));
    int blue = (int) (maxColor.getBlue() * ratio + minColor.getBlue() * (1 - ratio));
    Color gradient = new Color(red, green, blue);
    return gradient;
}

From source file:ColorUtil.java

/**
 * Return the hex name of a specified color.
 * //w w w  .ja v  a 2  s  .c o m
 * @param color  Color to get hex name of.
 * @return       Hex name of color: "rrggbb".
 */
public static String getHexName(Color color) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    String rHex = Integer.toString(r, 16);
    String gHex = Integer.toString(g, 16);
    String bHex = Integer.toString(b, 16);

    return (rHex.length() == 2 ? "" + rHex : "0" + rHex) + (gHex.length() == 2 ? "" + gHex : "0" + gHex)
            + (bHex.length() == 2 ? "" + bHex : "0" + bHex);
}

From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java

public static Image TransformColorToTransparency(BufferedImage image, Color c1, Color c2) {
    // Primitive test, just an example
    final int r1 = c1.getRed();
    final int g1 = c1.getGreen();
    final int b1 = c1.getBlue();
    final int r2 = c2.getRed();
    final int g2 = c2.getGreen();
    final int b2 = c2.getBlue();
    ImageFilter filter = new RGBImageFilter() {
        public final int filterRGB(int x, int y, int rgb) {
            int r = (rgb & 0xFF0000) >> 16;
            int g = (rgb & 0xFF00) >> 8;
            int b = rgb & 0xFF;
            if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
                // Set fully transparent but keep color
                return rgb & 0xFFFFFF;
            }//from  ww w. j ava 2s  .c  o  m
            return rgb;
        }
    };

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

From source file:ColorUtil.java

public static final Color add(Color c1, Color c2) {
    return c1 == null ? c2
            : c2 == null ? c1//  ww  w  .  j av a 2 s  .com
                    : new Color(Math.min(255, c1.getRed() + c2.getRed()),
                            Math.min(255, c1.getGreen() + c2.getGreen()),
                            Math.min(255, c1.getBlue() + c2.getBlue()), c1.getAlpha());
}

From source file:ColorUtil.java

/**
 * Check if a color is more dark than light. Useful if an entity of
 * this color is to be labeled: Use white label on a "dark" color and
 * black label on a "light" color.//from  w w w.java  2  s .c o  m
 *
 * @param color  Color to check.
 * @return       True if this is a "dark" color, false otherwise.
 */
public static boolean isDark(Color color) {
    float r = color.getRed() / 255.0f;
    float g = color.getGreen() / 255.0f;
    float b = color.getBlue() / 255.0f;

    return isDark(r, g, b);
}

From source file:Main.java

public static byte matchColor(Color c) {
    int i = 0;//from  www .j  a  va2  s. c  o m
    int combinatronix = 100000;
    for (int z = 0; z < csamples.length; z++) {
        Color grab = csamples[z];
        int calc = Math.abs(c.getRed() - grab.getRed()) + Math.abs(c.getGreen() - grab.getGreen())
                + Math.abs(c.getBlue() - grab.getBlue());
        if (calc < combinatronix) {
            combinatronix = calc;
            i = z;
        }
    }
    return (byte) i;
}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

private static Color addAlpha(Color color, int alpha) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}