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:Main.java

public static void main(String[] args) {
    Color myColor = Color.RED;

    System.out.println(myColor.getGreen());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage inputFile = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

    for (int x = 0; x < inputFile.getWidth(); x++) {
        for (int y = 0; y < inputFile.getHeight(); y++) {
            int rgba = inputFile.getRGB(x, y);
            Color col = new Color(rgba, true);
            col = new Color(255 - col.getRed(), 255 - col.getGreen(), 255 - col.getBlue());
            inputFile.setRGB(x, y, col.getRGB());
        }//from w  w w  . j a va2s  .  c om
    }

    File outputFile = new File("invert.png");
    ImageIO.write(inputFile, "png", outputFile);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    Color color = robot.getPixelColor(20, 20);

    System.out.println("Red   = " + color.getRed());
    System.out.println("Green = " + color.getGreen());
    System.out.println("Blue  = " + color.getBlue());
}

From source file:ColorUtil.java

public static Color makeTransparent(Color source, int alpha) {
    return new Color(source.getRed(), source.getGreen(), source.getBlue(), alpha);
}

From source file:ColorUtils.java

/**
 * Performs a somewhat subjective analysis of a color to determine how dark it looks to a user
 * //from  w ww  . j  a v  a2  s . c om
 * @param color The color to analyze
 * @return The darkness of the color
 */
public static float getDarkness(Color color) {
    float ret = color.getRed() + color.getGreen() + color.getBlue() / 10;
    ret /= (255 + 255 + 255 / 10);
    ret = 1 - ret;
    final float lightDarkBorder = 0.7f;
    if (ret > lightDarkBorder)
        ret = 0.5f + (ret - lightDarkBorder) * 0.5f / (1 - lightDarkBorder);
    else
        ret = ret * 0.5f / lightDarkBorder;
    return ret;
}

From source file:Main.java

public static Color averageColor(Color c1, Color c2) {
    return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
            (c1.getBlue() + c2.getBlue()) / 2);
}

From source file:Main.java

public static Color darken(Color c, float fr, float fg, float fb) {
    int r = c.getRed(), g = c.getGreen(), b = c.getBlue();
    return darken(c, (int) (r * (1f - fr)), (int) (g * (1f - fg)), (int) (b * (1f - fb)));
}

From source file:Main.java

public static Color darken(Color c, int r, int g, int b) {
    int or = c.getRed(), og = c.getGreen(), ob = c.getBlue();
    or -= r;/*from   w ww.  j  av a2s.c  o m*/
    og -= g;
    ob -= b;
    or = or < 0 ? 0 : or;
    or = or > 255 ? 255 : or;
    og = og < 0 ? 0 : og;
    og = og > 255 ? 255 : og;
    ob = ob < 0 ? 0 : ob;
    ob = ob > 255 ? 255 : ob;
    return new Color(or, og, ob);
}

From source file:GuiUtil.java

public static Color cloneColor(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue());
}

From source file:ColorUtil.java

public static boolean isDark(Color c) {
    return c.getRed() + c.getGreen() + c.getBlue() < 3 * 180;
}