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:uk.bl.wa.tika.parser.imagefeatures.FaceDetectionParser.java

private static Color maxBrightness(Color c) {
    float[] hsv = new float[3];
    Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsv);
    return new Color(Color.HSBtoRGB(hsv[0], hsv[1], 1.0f));
}

From source file:org.testeditor.dashboard.TableDurationTrend.java

/**
 * composes awt color from swt color RGB.
 * /*  w  w  w  . j av a  2  s  . c  om*/
 * @param color
 *            SWT
 * @return java.awt.Color
 */
public static java.awt.Color toAwtColor(org.eclipse.swt.graphics.Color color) {
    return new java.awt.Color(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:ml.hsv.java

public static void HSV2File(hsv hsvImage[][], int width, int height) throws IOException //store img output as hsv2file.png
{
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = image.getRaster();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int RGB = Color.HSBtoRGB(hsvImage[i][j].h, hsvImage[i][j].s, hsvImage[i][j].v);
            Color c = new Color(RGB);
            int temp[] = { c.getRed(), c.getGreen(), c.getBlue() };
            raster.setPixel(j, i, temp);
        }/*from ww w.  ja va  2  s. co m*/
    }
    ImageIO.write(image, "PNG",
            new File("/home/shinchan/FinalProject/PaperImplementation/Eclipse/ML/output/hsv2file.png"));
}

From source file:Main.java

/**
 * Write a {@link Color} value into XML output.
 *
 * @param value// w  w w  . j  a  v  a  2s.co m
 * value to write
 *
 * @return
 * XML string
 *
 * @throws IllegalArgumentException
 * if a validation error occured
 */
public static String printColor(Color value) {
    if (value == null) {
        throw new IllegalArgumentException("The provided color is invalid!");
    }

    String r = Integer.toHexString(value.getRed()).trim();
    if (r.length() == 1)
        r = "0" + r;
    String g = Integer.toHexString(value.getGreen()).trim();
    if (g.length() == 1)
        g = "0" + g;
    String b = Integer.toHexString(value.getBlue()).trim();
    if (b.length() == 1)
        b = "0" + b;
    return "#" + r + g + b;
}

From source file:de.bund.bfr.jung.JungUtils.java

private static Paint mixWith(Paint paint, Color mix) {
    if (paint instanceof Color) {
        Color c = (Color) paint;

        return new Color((c.getRed() + mix.getRed()) / 2, (c.getGreen() + mix.getGreen()) / 2,
                (c.getBlue() + mix.getBlue()) / 2, (c.getAlpha() + mix.getAlpha()) / 2);
    } else if (paint instanceof TexturePaint) {
        BufferedImage texture = ((TexturePaint) paint).getImage();
        BufferedImage mixed = new BufferedImage(texture.getWidth(), texture.getHeight(), texture.getType());

        for (int x = 0; x < texture.getWidth(); x++) {
            for (int y = 0; y < texture.getHeight(); y++) {
                mixed.setRGB(x, y, ((Color) mixWith(new Color(texture.getRGB(x, y)), mix)).getRGB());
            }/*from ww  w . j av  a  2  s  .  c om*/
        }

        return new TexturePaint(mixed, new Rectangle(mixed.getWidth(), mixed.getHeight()));
    } else {
        return paint;
    }
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractGrayColor(BufferedImage source) {
    //Extracts the gray value from the pixels at the source by 
    //calculating the average of the RGB value at the given pixel.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3;
            values[(i * imageWidth) + j] = value;
        }// w w  w . j  a va  2  s  .c o  m
    }

    return values;
}

From source file:ColorUtil.java

/**
 * Make a color darker./*from  www . j a  v  a  2  s . c  om*/
 * 
 * @param color     Color to make darker.
 * @param fraction  Darkness fraction.
 * @return          Darker color.
 */
public static Color darker(Color color, double fraction) {
    int red = (int) Math.round(color.getRed() * (1.0 - fraction));
    int green = (int) Math.round(color.getGreen() * (1.0 - fraction));
    int blue = (int) Math.round(color.getBlue() * (1.0 - fraction));

    if (red < 0)
        red = 0;
    else if (red > 255)
        red = 255;
    if (green < 0)
        green = 0;
    else if (green > 255)
        green = 255;
    if (blue < 0)
        blue = 0;
    else if (blue > 255)
        blue = 255;

    int alpha = color.getAlpha();

    return new Color(red, green, blue, alpha);
}

From source file:ColorUtil.java

/**
 * Make a color lighter.//from  ww  w . j  av  a  2s  .  c o m
 * 
 * @param color     Color to make lighter.
 * @param fraction  Darkness fraction.
 * @return          Lighter color.
 */
public static Color lighter(Color color, double fraction) {
    int red = (int) Math.round(color.getRed() * (1.0 + fraction));
    int green = (int) Math.round(color.getGreen() * (1.0 + fraction));
    int blue = (int) Math.round(color.getBlue() * (1.0 + fraction));

    if (red < 0)
        red = 0;
    else if (red > 255)
        red = 255;
    if (green < 0)
        green = 0;
    else if (green > 255)
        green = 255;
    if (blue < 0)
        blue = 0;
    else if (blue > 255)
        blue = 255;

    int alpha = color.getAlpha();

    return new Color(red, green, blue, alpha);
}

From source file:ColorUtil.java

public static Color blend(Color c1, Color c2, double v) {
    double v2 = 1 - v;
    return c1 == null ? (c2 == null ? null : c2)
            : c2 == null ? c1//from  www  .j a v  a  2  s.  co m
                    : new Color(Math.min(255, (int) (c1.getRed() * v2 + c2.getRed() * v)),
                            Math.min(255, (int) (c1.getGreen() * v2 + c2.getGreen() * v)),
                            Math.min(255, (int) (c1.getBlue() * v2 + c2.getBlue() * v)),
                            Math.min(255, (int) (c1.getAlpha() * v2 + c2.getAlpha() * v)));
}

From source file:net.tbnr.gearz.game.kits.GearzKitItem.java

static GearzKitItem fromJsonObject(JSONObject object) throws GearzKitReadException {
    String materialName;/*w ww. j av  a2 s  .  c  om*/
    Integer quantity = 1;
    try {
        materialName = object.getString("item_type");
    } catch (JSONException ex) {
        throw GearzKit.exceptionFromJSON("Could not read class", ex);
    }
    try {
        quantity = object.getInt("quantity");
    } catch (JSONException ignored) {
    }
    Material material = Material.getMaterial(materialName);
    if (material == null) {
        throw new GearzKitReadException("Invalid Material Specified: " + materialName);
    }
    JSONArray enchants = null;
    Short data = null;
    try {
        if (object.has("enchants")) {
            enchants = object.getJSONArray("enchants");
        }
        if (object.has("data")) {
            data = (short) object.getInt("data");
        }
    } catch (JSONException ignored) {
    }
    HashMap<Enchantment, Integer> enchantmentMap = null;
    if (enchants != null) {
        enchantmentMap = new HashMap<>();
        for (int x = 0; x < enchants.length(); x++) {
            try {
                JSONObject enchantObject = enchants.getJSONObject(x);
                String enchant_name = enchantObject.getString("name");
                int level = enchantObject.getInt("level");
                Enchantment e = Enchantment.getByName(enchant_name);
                if (e == null || level < 1) {
                    throw new GearzKitReadException(
                            "Invalid Enchantment " + x + " " + enchant_name + " " + level);
                }
                enchantmentMap.put(e, level);
                Gearz.getInstance().debug("Added enchant " + x + " " + e.getName() + ":" + level);
            } catch (JSONException e) {
                throw GearzKit.exceptionFromJSON("Could not read enchantment " + x, e);
            }
        }
    }
    GearzItemMeta itemMeta = new GearzItemMeta();
    try {
        if (object.has("title")) {
            itemMeta.setTitle(object.getString("title"));
        }
        if (object.has("lore")) {
            JSONArray loreJSON = object.getJSONArray("lore");
            List<String> lore = new ArrayList<>();
            for (int y = 0; y < loreJSON.length(); y++) {
                lore.add(loreJSON.getString(y));
            }
            itemMeta.setLore(lore);
        }
        if (object.has("owner")) {
            itemMeta.setOwner(object.getString("owner"));
        }
        if (object.has("color")) {
            Color decode = Color.decode(object.getString("color"));
            org.bukkit.Color color = org.bukkit.Color.fromRGB(decode.getRed(), decode.getGreen(),
                    decode.getBlue());
            itemMeta.setColor(color);
        }
    } catch (JSONException ex) {
        throw GearzKit.exceptionFromJSON("Could not read meta", ex);
    }
    GearzKitItem gearzKitItem = new GearzKitItem(material, quantity, itemMeta);
    if (enchantmentMap != null) {
        gearzKitItem.setEnchantments(enchantmentMap);
    }
    if (data != null) {
        gearzKitItem.setData(data);
    }
    return gearzKitItem;
}