Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

Returns the red 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.getRed());

}

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: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());
        }// w w  w . ja v a 2s.co m
    }

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

}

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

/**
 * Performs a somewhat subjective analysis of a color to determine how dark it looks to a user
 * //from ww w. j a  v  a2  s  .  co  m
 * @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:Utils.java

public static String getHTMLColorString(Color color) {
    String red = Integer.toHexString(color.getRed());
    String green = Integer.toHexString(color.getGreen());
    String blue = Integer.toHexString(color.getBlue());

    return "#" + (red.length() == 1 ? "0" + red : red) + (green.length() == 1 ? "0" + green : green)
            + (blue.length() == 1 ? "0" + blue : blue);
}

From source file:ColorUtils.java

/**
 * Lightens a color by a given amount/*from   w ww .  jav a2  s.com*/
 * 
 * @param color The color to lighten
 * @param amount The amount to lighten the color. 0 will leave the color unchanged; 1 will make
 *        the color completely white
 * @return The bleached color
 */
public static Color bleach(Color color, float amount) {
    int red = (int) ((color.getRed() * (1 - amount) / 255 + amount) * 255);
    int green = (int) ((color.getGreen() * (1 - amount) / 255 + amount) * 255);
    int blue = (int) ((color.getBlue() * (1 - amount) / 255 + amount) * 255);
    return new Color(red, green, blue);
}

From source file:ColorUtils.java

/**
 * Darkens a color by a given amount//w  w w  . j a  va  2s .com
 * 
 * @param color The color to darken
 * @param amount The amount to darken the color. 0 will leave the color unchanged; 1 will make
 *        the color completely black
 * @return The stained color
 */
public static Color stain(Color color, float amount) {
    int red = (int) ((color.getRed() * (1 - amount) / 255) * 255);
    int green = (int) ((color.getGreen() * (1 - amount) / 255) * 255);
    int blue = (int) ((color.getBlue() * (1 - amount) / 255) * 255);
    return new Color(red, green, blue);
}

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)));
}