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:edu.scripps.fl.curves.plot.CurvePlotDrawingSupplier.java

private static Color toGreyScale(Color c) {
    int rgb = (int) (((double) c.getRed() * 0.299) + ((double) c.getGreen() * 0.587)
            + ((double) c.getBlue() * 0.114));
    if (rgb > 255)
        rgb = 255;//from ww w  .j  a  v a2  s .c o m
    return new Color(rgb, rgb, rgb);
}

From source file:Main.java

public static byte[] getCompressedImage(byte[] rgb) {

    BufferedImage image;//from  ww w.ja  v a2s.  c o  m
    int width;
    int height;

    try {
        image = ImageIO.read(new ByteArrayInputStream(rgb));
        width = image.getWidth();
        height = image.getHeight();

        for (int i = 0; i < height; i++) {

            for (int j = 0; j < width; j++) {

                Color c = new Color(image.getRGB(j, i));
                int red = (int) (c.getRed() * 0.299);
                int green = (int) (c.getGreen() * 0.587);
                int blue = (int) (c.getBlue() * 0.114);
                Color newColor = new Color(red + green + blue,

                        red + green + blue, red + green + blue);

                image.setRGB(j, i, newColor.getRGB());
            }
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();
        baos.close();

        return imageInByte;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * Linear interpolation./*w w w  . j  a  va  2s .  c o  m*/
 * @param color0
 * @param color1
 * @param amount
 * @return
 */
public static Color Lerp(Color color0, Color color1, double amount) {
    int r = (int) Lerp(color0.getRed(), color1.getRed(), amount);
    int g = (int) Lerp(color0.getGreen(), color1.getGreen(), amount);
    int b = (int) Lerp(color0.getBlue(), color1.getBlue(), amount);
    int a = (int) Lerp(color0.getAlpha(), color1.getAlpha(), amount);
    if (r > 255)
        r = 255;
    if (r < 0)
        r = 0;
    if (g > 255)
        g = 255;
    if (g < 0)
        g = 0;
    if (b > 255)
        b = 255;
    if (b < 0)
        b = 0;
    if (a > 255)
        a = 255;
    if (a < 0)
        a = 0;
    return new Color(r, g, b, a);
}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.scale.ColorDecorator.java

public static double lum(Color color) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    return .299 * r + .587 * g + .114 * b;
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param color/*from  w  w  w .  ja  v a  2 s.  c  o m*/
 * @param alpha
 * @return
 */
public static Color withAlpha(Color color, float alpha) {
    Color ca = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (alpha * 255.0f));
    return ca;
}

From source file:Main.java

public static Color adjust2(Color original, double value, int maximumrange) {
    if (value > 1)
        value = 1;//from   ww w .  j a  va  2s .co m
    if (value < 0)
        value = 0;

    int r = original.getRed();
    int g = original.getGreen();
    int b = original.getBlue();

    double nah = value * maximumrange;

    r += (int) nah;
    g += (int) nah;
    b += (int) nah;

    r = colorSnap(r);
    g = colorSnap(g);
    b = colorSnap(b);
    return new Color(r, g, b, original.getAlpha());
}

From source file:PaintUtils.java

/** Paints 3 different strokes around a shape to indicate focus.
 * The widest stroke is the most transparent, so this achieves a nice
 * "glow" effect.//  w  w  w  .  ja v  a  2s  .  c  o  m
 * <P>The catch is that you have to render this underneath the shape,
 * and the shape should be filled completely.
 * 
 * @param g the graphics to paint to
 * @param shape the shape to outline
 * @param biggestStroke the widest stroke to use.
 */
public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) {
    Color focusColor = getFocusRingColor();
    Color[] focusArray = new Color[] {
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255),
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170),
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) };
    g.setStroke(new BasicStroke(biggestStroke));
    g.setColor(focusArray[2]);
    g.draw(shape);
    g.setStroke(new BasicStroke(biggestStroke - 1));
    g.setColor(focusArray[1]);
    g.draw(shape);
    g.setStroke(new BasicStroke(biggestStroke - 2));
    g.setColor(focusArray[0]);
    g.draw(shape);
    g.setStroke(new BasicStroke(1));
}

From source file:com.github.fritaly.graphml4j.Utils.java

/**
 * Encodes the given color into an hexadecimal string like "#RRGGBBAA" or
 * "#RRGGBB" (whether the transparency is set to 0).
 *
 * @param color//from   ww w. j a va 2 s.  c o m
 *            a color to encode. Can't be null.
 * @return a string representing the encoded color.
 */
static String encode(Color color) {
    Validate.notNull(color, "The given color is null");

    if (color.getAlpha() == 255) {
        return String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
    } else {
        return String.format("#%02X%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue(),
                color.getAlpha());
    }
}

From source file:ColorUtil.java

public static final Color mult(Color c, double amount) {
    return c == null ? null
            : new Color(Math.min(255, (int) (c.getRed() * amount)),
                    Math.min(255, (int) (c.getGreen() * amount)), Math.min(255, (int) (c.getBlue() * amount)),
                    c.getAlpha());//from  w w w .  ja  va 2s .  c  o  m
}

From source file:chiliad.parser.pdf.model.MToken.java

public static String colorToRgba(Color c) {
    return "rgba(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() / 255 + ")";
}