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: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;
        }/*from www  . j  a  v  a2s  .  c  om*/
    }

    return values;
}

From source file:com.glaf.core.util.Tools.java

public static String javaColorToCSSColor(Color paramColor) {
    StringBuffer localStringBuffer = new StringBuffer(30);
    localStringBuffer.append("rgb(");
    localStringBuffer.append(paramColor.getRed());
    localStringBuffer.append(',');
    localStringBuffer.append(paramColor.getGreen());
    localStringBuffer.append(',');
    localStringBuffer.append(paramColor.getBlue());
    localStringBuffer.append(')');
    return localStringBuffer.toString();
}

From source file:org.fhcrc.cpl.viewer.mrm.Utils.java

public static Color paleColor(Color origColor) {

    int origRed = origColor.getRed();
    int origGreen = origColor.getGreen();
    int origBlue = origColor.getBlue();

    int maxColorVal = Math.max(Math.max(origRed, origGreen), origBlue);
    if (maxColorVal + PALE_CONSTANT > 255) {
        int adjust = (maxColorVal + PALE_CONSTANT) - 255;
        origRed = Math.max(0, origRed - adjust);
        origGreen = Math.max(0, origGreen - adjust);
        origBlue = Math.max(0, origBlue - adjust);
    }/*ww  w.java 2s .  com*/

    Color paleColor = new Color(origRed + PALE_CONSTANT, origGreen + PALE_CONSTANT, origBlue + PALE_CONSTANT);
    return paleColor;
}

From source file:umontreal.ssj.charts.SSJCategorySeriesCollection.java

/**
 * Converts a java Color object into a friendly and readable LaTeX/xcolor string.
 *
 * @param   color    in color./* ww  w . j  a  v  a  2  s .  co  m*/
 * @return           friendly color with string format as possible, null otherwise.
 */
protected static String detectXColorClassic(Color color) {
    String retour = null;

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

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

static GearzKitItem fromJsonObject(JSONObject object) throws GearzKitReadException {
    String materialName;//from   ww  w. j a v  a 2 s. c o m
    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;
}

From source file:umontreal.iro.lecuyer.charts.SSJCategorySeriesCollection.java

protected static String detectXColorClassic(Color color) {
    String retour = null;//  w  ww.  java 2 s  .  c om

    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le parametre de transparence : Alpha
    if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
        return "green";
    else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
        return "red";
    else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
        return "white";
    else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
        return "gray";
    else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
        return "black";
    else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
        return "yellow";
    else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue()
            && green == Color.MAGENTA.getGreen())
        return "magenta";
    else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
        return "cyan";
    else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
        return "blue";
    else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
            && green == Color.DARK_GRAY.getGreen())
        return "darkgray";
    else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
            && green == Color.LIGHT_GRAY.getGreen())
        return "lightgray";
    else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
        return "orange";
    else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
        return "pink";

    if (red == 192 && blue == 128 && green == 64)
        return "brown";
    else if (red == 128 && blue == 128 && green == 0)
        return "olive";
    else if (red == 128 && blue == 0 && green == 128)
        return "violet";
    else if (red == 192 && blue == 0 && green == 64)
        return "purple";
    else
        return null;
}

From source file:OAT.ui.util.UiUtil.java

/**
 * Returns the RGB components (rrr, ggg, bbb) in the range of 0-255.
 *
 * @param color/*from  w  w  w .j ava2 s .  co  m*/
 * @return
 */
public static String getColorRGB(Color color) {
    return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(File input) throws IOException {
    BufferedImage image;/*from w  ww . ja  v  a  2s.  c o  m*/
    int width, height;

    // File input = new File(ip);
    image = ImageIO.read(input);
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }
    // HSV2File(hsvImage,width,height); debugging code removed      
    return hsvImage;
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(String ip) throws IOException {
    BufferedImage image;/*from  www.  j av a 2 s .c  o  m*/
    int width, height;

    File input = new File(ip);
    image = ImageIO.read(input);
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }

    HSV2File(hsvImage, width, height);

    return hsvImage;
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

public static int calculateBrightness(@Nonnull final Color color) {
    return (int) Math.sqrt(color.getRed() * color.getRed() * .241d + color.getGreen() * color.getGreen() * .691d
            + color.getBlue() * color.getBlue() * .068d);
}