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:net.sf.jabref.gui.maintable.MainTable.java

private static Color mixColors(Color one, Color two) {
    return new Color((one.getRed() + two.getRed()) / 2, (one.getGreen() + two.getGreen()) / 2,
            (one.getBlue() + two.getBlue()) / 2);
}

From source file:com.t_oster.visicut.misc.Helper.java

public static String toHtmlRGB(Color col) {
    String r = Integer.toHexString(col.getRed());
    String g = Integer.toHexString(col.getGreen());
    String b = Integer.toHexString(col.getBlue());
    return "#" + (r.length() == 1 ? "0" + r : r) + (g.length() == 1 ? "0" + g : g)
            + (b.length() == 1 ? "0" + b : b);
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected static final LookupPaintScale createLUT(final int ncol, final float vmin, final float vmax,
        final Color start, final Color med, final Color end) {
    final float[][] colors = new float[][] {
            { start.getRed() / 255f, start.getGreen() / 255f, start.getBlue() / 255f, start.getAlpha() / 255f },
            { med.getRed() / 255f, med.getGreen() / 255f, med.getBlue() / 255f, med.getAlpha() / 255f },
            { end.getRed() / 255f, end.getGreen() / 255f, end.getBlue() / 255f, end.getAlpha() / 255f } };
    final float[] limits = new float[] { 0, 0.5f, 1 };
    final LookupPaintScale lut = new LookupPaintScale(vmin, vmax, med);
    float val;
    float r, g, b, a;
    for (int j = 0; j < ncol; j++) {
        val = j / (ncol - 0.99f);
        int i = 0;
        for (i = 0; i < limits.length; i++) {
            if (val < limits[i]) {
                break;
            }// ww w  .  ja va 2  s .c om
        }
        i = i - 1;
        r = colors[i][0] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][0] - colors[i][0]);
        g = colors[i][1] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][1] - colors[i][1]);
        b = colors[i][2] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][2] - colors[i][2]);
        a = colors[i][3] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][3] - colors[i][3]);
        lut.add(val * (vmax - vmin) + vmin, new Color(r, g, b, a));
    }
    return lut;
}

From source file:ala.soils2sat.DrawingUtils.java

public static Color generateRandomColor(Color mix) {
    Random random = new Random();
    int red = random.nextInt(256);
    int green = random.nextInt(256);
    int blue = random.nextInt(256);

    // mix the color
    if (mix != null) {
        red = (red + mix.getRed()) / 2;/*from w  w  w . j  ava 2 s  .c  o  m*/
        green = (green + mix.getGreen()) / 2;
        blue = (blue + mix.getBlue()) / 2;
    }

    Color color = new Color(red, green, blue);
    return color;
}

From source file:co.foldingmap.mapImportExport.SvgExporter.java

/**
  * Returns the hex version of a Color object.  
  * Output is red, green, blue./*w ww.j  a  va  2s.co  m*/
  * 
  * @param c
  * @return 
  */
public static String getHexColor(Color c) {
    String hexColor, b, g, r;

    b = Integer.toHexString(c.getBlue());
    g = Integer.toHexString(c.getGreen());
    r = Integer.toHexString(c.getRed());

    if (b.length() == 1)
        b = "0" + b;

    if (g.length() == 1)
        g = "0" + g;

    if (r.length() == 1)
        r = "0" + r;

    hexColor = r + g + b;

    return hexColor;
}

From source file:cn.z.Ocr5.java

public static BufferedImage removeBackgroud(File picFile) throws Exception {

    BufferedImage img = ImageIO.read(picFile);
    final int width = img.getWidth();
    final int height = img.getHeight();

    // int blackThreshold = 300;

    // img.getMinX() img.getMinY()
    for (int x = img.getMinX(); x < width; x++) {
        for (int y = img.getMinY(); y < height; y++) {

            Color color = new Color(img.getRGB(x, y));
            if ((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { //
                img.setRGB(x, y, Color.WHITE.getRGB());
            } else if ((color.getRed() + color.getGreen() + color.getBlue()) < 400) {
                img.setRGB(x, y, Color.BLACK.getRGB());
            }//w  w  w  .j  a  va  2s . com

            int nearly = 0;
            int vertical = 0;
            int horizontal = 0;

            if (x > 0) {
                Color leftColor = new Color(img.getRGB(x - 1, y));
                if ((leftColor.getRed() + leftColor.getGreen() + leftColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (x < width - 1) {
                Color rightColor = new Color(img.getRGB(x + 1, y));
                if ((rightColor.getRed() + rightColor.getGreen() + rightColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (y > 0) {
                Color topColor = new Color(img.getRGB(x, y - 1));
                if ((topColor.getRed() + topColor.getGreen() + topColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }
            if (y < height - 1) {
                Color bottomColor = new Color(img.getRGB(x, y + 1));
                if ((bottomColor.getRed() + bottomColor.getGreen() + bottomColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }

            if (x > 0 && y > 0) {
                Color leftTopColor = new Color(img.getRGB(x - 1, y - 1));
                if ((leftTopColor.getRed() + leftTopColor.getGreen() + leftTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y < height - 1) {
                Color rightBottomColor = new Color(img.getRGB(x + 1, y + 1));
                if ((rightBottomColor.getRed() + rightBottomColor.getGreen()
                        + rightBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y > 0) {
                Color rightTopColor = new Color(img.getRGB(x + 1, y - 1));
                if ((rightTopColor.getRed() + rightTopColor.getGreen() + rightTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x > 0 && y < height - 1) {
                Color leftBottomColor = new Color(img.getRGB(x - 1, y + 1));
                if ((leftBottomColor.getRed() + leftBottomColor.getGreen() + leftBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }

            if (nearly < 2) {
                img.setRGB(x, y, Color.WHITE.getRGB());
            }
            /*
            if (horizontal < 1 && vertical > 0) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            if (horizontal > 0 && vertical < 1) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            /*
            if (isWhite(img.getRGB(x, y), whiteThreshold) == 1) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            } else {
            img.setRGB(x, y, Color.BLACK.getRGB());
            }
                    
                    
            if (getColorBright(img.getRGB(x, y)) < 100) {
            int count = isBlack(img.getRGB(x - 1, y), blackThreshold) + isBlack(img.getRGB(x + 1, y), blackThreshold) + isBlack(img.getRGB(x, y - 1), blackThreshold) + isBlack(img.getRGB(x, y + 1), blackThreshold) + isBlack(img.getRGB(x + 1, y + 1), blackThreshold) + isBlack(img.getRGB(x - 1, y - 1), blackThreshold) + isBlack(img.getRGB(x + 1, y -1 ), blackThreshold) + isBlack(img.getRGB(x - 1, y + 1), blackThreshold);
            System.out.println(count);
            if (count < 2) {
                img.setRGB(x, y, Color.WHITE.getRGB());
            }
            //     img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            //                if(getColorBright(img.getRGB(x, y)) > 600) {
            //                    img.setRGB(x, y, Color.WHITE.getRGB());
            //                } else {
            //                    /*
            //                    // ?Graphics2D
            //                    Graphics2D g2d = img.createGraphics();
            //                    // ?
            //                    // 1.0f? 0-1.0????
            //                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f));
            //                    // 
            //                    g2d.setColor(new Color(255,0,0));
            //                    g2d.setStroke(new BasicStroke(1));
            //                    // g2d.draw
            //                    // 
            //                    // ? ?
            //                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            //                    g2d.dispose();
            //                    */
            //
            //                    img.setRGB(x, y, Color.BLACK.getRGB());
            //                    /*
            //                    System.out.println(getColorBright(img.getRGB(x, y)) + ":");
            //                    System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1)));
            //                    System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1)));
            //                    System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1)));
            //                    */
            //
            //                    /*
            //                    int i = 0;
            //                    i = ((x < width - 1) && getColorBright(img.getRGB(x + 1, y)) < 30)? i + 1 : i;
            //                    i = ((x < width - 1) && (y < height - 1) && getColorBright(img.getRGB(x + 1, y + 1)) < 30)? i + 1 : i;
            //                    i = ((y < height - 1) && getColorBright(img.getRGB(x, y + 1)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && getColorBright(img.getRGB(x - 1, y)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && (y > 0) && getColorBright(img.getRGB(x - 1, y - 1)) < 30)? i + 1 : i;
            //                    i = ((y > 0) && getColorBright(img.getRGB(x, y - 1)) < 30)? i + 1 : i;
            //                    i = ((x < width - 1) && (y > 0) && getColorBright(img.getRGB(x + 1, y - 1)) < 30)? i + 1 : i;
            //                    i = ((x > 0) && (y < height - 1) && getColorBright(img.getRGB(x - 1, y + 1)) < 30)? i + 1 : i;
            //
            //                    if(i > 1) {
            //                        img.setRGB(x, y, Color.BLACK.getRGB());
            //                    } else {
            //                        img.setRGB(x, y, Color.WHITE.getRGB());
            //                    }
            //                    */
            //                }

            /*
            int i = 0;
            i = (getColorBright(img.getRGB(x + 1, y)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x + 1, y + 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x, y + 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x - 1, y)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x - 1, y - 1)) == 0)? i + 1 : i;
            i = (getColorBright(img.getRGB(x, y - 1)) == 0)? i + 1 : i;
                    
            System.out.println(getColorBright(img.getRGB(x, y)) + ":");
            System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1)));
            System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1)));
            System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1)));
            if(getColorBright(img.getRGB(x, y)) == 0 &&  i < 3) {
            img.setRGB(x, y, Color.WHITE.getRGB());
            }
            */

            /*
            // ?for????
            // ??object
            Object data = img.getRaster().getDataElements(x, y, null);
            int red = img.getColorModel().getRed(data);
            int blue = img.getColorModel().getBlue(data);
            int green = img.getColorModel().getGreen(data);
            System.out.println((red + blue + green) + "-" + getColorBright(img.getRGB(x, y)));
            red = (red * 3 + green * 6 + blue * 1)/10;
            green = red;
            blue = green;
                    
            // r?g?b?rgbbufferedImage????rgbrgb8388608?255*255*255?16777216
            int rgb = (red * 256 + green) * 256 + blue;
            if(rgb > 8388608) {
            rgb = rgb - 16777216;
            }
            // rgb
            img.setRGB(x, y, rgb);
            */

        }
    }
    // img = img.getSubimage(1, 1, img.getWidth() - 2, img.getHeight() - 2);
    return img;
}

From source file:org.kalypso.kalypsosimulationmodel.utils.SLDHelper.java

/**
 * if lightestColor is null, than WHITE (0, 0, 0) is used instead
 *//*www.j a va2  s  . co  m*/
private static StyledLayerDescriptor createRasterSLD(final double minValue, final double maxValue,
        final int numberOfIntervals, final Color lightestColor, final Color darkestColor,
        final String styleName, final String styleTitle, final IProgressMonitor monitor) throws CoreException {
    final TreeMap<Double, ColorMapEntry> colorMap = new TreeMap<>();
    final FeatureTypeStyle style = StyleFactory.createFeatureTypeStyle();

    final int rd = darkestColor.getRed();
    final int gd = darkestColor.getGreen();
    final int bd = darkestColor.getBlue();
    final int rl = lightestColor == null ? 0 : lightestColor.getRed();
    final int gl = lightestColor == null ? 0 : lightestColor.getGreen();
    final int bl = lightestColor == null ? 0 : lightestColor.getBlue();
    for (int i = 0; i <= numberOfIntervals; i++) {
        final double ratio = (double) i / (double) numberOfIntervals;
        final double quantity = Math.rint(1000.0 * (minValue + (maxValue - minValue) * ratio)) / 1000.0;

        // making lighter color (color.brighter() is not so good...)
        final int r = (int) (rd * ratio + rl * (1 - ratio));
        final int g = (int) (gd * ratio + gl * (1 - ratio));
        final int b = (int) (bd * ratio + bl * (1 - ratio));

        final ColorMapEntry colorMapEntry = new ColorMapEntry_Impl(new Color(r, g, b),
                DEFAULT_RASTER_FILLOPACITY, quantity, ""); //$NON-NLS-1$
        colorMap.put(quantity, colorMapEntry);
        if (monitor.isCanceled())
            throw new CoreException(Status.CANCEL_STATUS);
    }

    final RasterSymbolizer rasterSymbolizer = new RasterSymbolizer_Impl(null, colorMap, null, null);
    final Rule rule = StyleFactory.createRule(rasterSymbolizer);
    style.addRule(rule);

    final FeatureTypeStyle[] featureTypeStyles = new FeatureTypeStyle[] { style };
    final Style[] styles = new Style[] {
            StyleFactory.createUserStyle(styleName, styleTitle, null, false, featureTypeStyles) };
    final org.kalypsodeegree.graphics.sld.Layer[] layers = new org.kalypsodeegree.graphics.sld.Layer[] {
            SLDFactory.createNamedLayer(LAYER_NAME, null, styles) };
    return SLDFactory.createStyledLayerDescriptor(layers);
}

From source file:net.sf.firemox.tools.Picture.java

/**
 * Return the border color of this card. If the picture of this card is not
 * <code>null</code> the returned color corresponds to the pixel placed on
 * the topmost leftmost pixel.//from  w w  w .j a  v a  2  s .  co  m
 * 
 * @return the border color of this card.
 */
private static Color getBorderColor(BufferedImage image) {
    Color borderColor;
    // The border color is not yet cached
    if (CardFactory.borderColor != null) {
        // manual border
        borderColor = CardFactory.borderColor;
    } else {
        // auto border
        if (image != null) {
            borderColor = new Color(image.getRGB(0, 0));
            if (borderColor.getRed() > 175 && borderColor.getGreen() > 175 && borderColor.getBlue() > 175) {
                borderColor = Color.WHITE.darker();
            } else {
                borderColor = Color.BLACK.brighter();
            }
        } else {
            borderColor = CardFactory.borderColor;
        }
    }
    return borderColor;
}

From source file:Main.java

public static String displayPropertiesToCSS(Font font, Color fg) {
    StringBuffer rule = new StringBuffer("body {");
    if (font != null) {
        rule.append(" font-family: ");
        rule.append(font.getFamily());//from   www. java 2  s. com
        rule.append(" ; ");
        rule.append(" font-size: ");
        rule.append(font.getSize());
        rule.append("pt ;");
        if (font.isBold()) {
            rule.append(" font-weight: 700 ; ");
        }
        if (font.isItalic()) {
            rule.append(" font-style: italic ; ");
        }
    }
    if (fg != null) {
        rule.append(" color: #");
        if (fg.getRed() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getRed()));
        if (fg.getGreen() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getGreen()));
        if (fg.getBlue() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getBlue()));
        rule.append(" ; ");
    }
    rule.append(" }");
    return rule.toString();
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Paint mixColors(Color backgroundColor, List<Color> colors, List<Double> alphas,
        boolean checkedInsteadOfStriped) {
    double rb = backgroundColor.getRed() / 255.0;
    double gb = backgroundColor.getGreen() / 255.0;
    double bb = backgroundColor.getBlue() / 255.0;
    double ab = backgroundColor.getAlpha() / 255.0;
    List<Color> cs = new ArrayList<>();

    for (int i = 0; i < colors.size(); i++) {
        double alpha = alphas.get(i);

        if (alpha > 0.0) {
            double r = colors.get(i).getRed() / 255.0 * alpha + rb * (1 - alpha);
            double g = colors.get(i).getGreen() / 255.0 * alpha + gb * (1 - alpha);
            double b = colors.get(i).getBlue() / 255.0 * alpha + bb * (1 - alpha);
            double a = colors.get(i).getAlpha() / 255.0 * alpha + ab * (1 - alpha);

            cs.add(new Color((float) r, (float) g, (float) b, (float) a));
        }//  w  w  w  . ja va  2s.  c  o m
    }

    if (cs.isEmpty()) {
        return backgroundColor;
    } else if (cs.size() == 1) {
        return cs.get(0);
    }

    BufferedImage img;
    int size = cs.size() * (checkedInsteadOfStriped ? EDGE_TEXTURE_SIZE : NODE_TEXTURE_SIZE);

    if (checkedInsteadOfStriped) {
        img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            for (int y = 0; y < size; y++) {
                img.setRGB(x, y, cs.get((x / EDGE_TEXTURE_SIZE + y / EDGE_TEXTURE_SIZE) % cs.size()).getRGB());
            }
        }
    } else {
        img = new BufferedImage(size, 1, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            img.setRGB(x, 0, cs.get(x / NODE_TEXTURE_SIZE).getRGB());
        }
    }

    return new TexturePaint(img, new Rectangle(img.getWidth(), img.getHeight()));
}