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:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java

public static String color2html(final Color c, final boolean alpha) {
    final String ac = Integer.toHexString(c.getAlpha()).toUpperCase(Locale.ENGLISH);
    final String rc = Integer.toHexString(c.getRed()).toUpperCase(Locale.ENGLISH);
    final String gc = Integer.toHexString(c.getGreen()).toUpperCase(Locale.ENGLISH);
    final String bc = Integer.toHexString(c.getBlue()).toUpperCase(Locale.ENGLISH);

    final StringBuilder result = new StringBuilder(7);
    result.append('#');
    if (alpha) {/* w ww.  j  ava2s .co  m*/
        if (ac.length() == 1) {
            result.append('0');
        }
        result.append(ac);
    }
    if (rc.length() == 1) {
        result.append('0');
    }
    result.append(rc);
    if (gc.length() == 1) {
        result.append('0');
    }
    result.append(gc);
    if (bc.length() == 1) {
        result.append('0');
    }
    result.append(bc);

    return result.toString();
}

From source file:com.lingxiang2014.util.ImageUtils.java

private static String toHexEncoding(Color color) {
    String R, G, B;//from   w w w  .  j ava  2 s  .  co  m
    StringBuffer stringBuffer = new StringBuffer();
    R = Integer.toHexString(color.getRed());
    G = Integer.toHexString(color.getGreen());
    B = Integer.toHexString(color.getBlue());
    R = R.length() == 1 ? "0" + R : R;
    G = G.length() == 1 ? "0" + G : G;
    B = B.length() == 1 ? "0" + B : B;
    stringBuffer.append("#");
    stringBuffer.append(R);
    stringBuffer.append(G);
    stringBuffer.append(B);
    return stringBuffer.toString();
}

From source file:imageprocessingproject.ImageHistogram.java

public static BufferedImage autoContrastImage(BufferedImage image) {
    createContrastLUT(image);//from w w w  .  j  a  v  a 2s  .c o  m

    int height = image.getHeight();
    int width = image.getWidth();
    int r, g, b;
    Color c;

    BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            r = (int) (255 * contrast_lut[c.getRed()]);
            g = (int) (255 * contrast_lut[c.getGreen()]);
            b = (int) (255 * contrast_lut[c.getBlue()]);
            tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB());
        }
    }

    return tempImage;
}

From source file:smanilov.mandelbrot.compute.Computer.java

/**
 * Mixes the given colors in the given proportion.
 *///w  w  w  . j  a va  2  s.co m
private static Color mixColors(Color c1, Color c2, double proportion) {
    Color result = new Color((int) (c1.getRed() * (1 - proportion) + c2.getRed() * proportion),
            (int) (c1.getGreen() * (1 - proportion) + c2.getGreen() * proportion),
            (int) (c1.getBlue() * (1 - proportion) + c2.getBlue() * proportion));
    return result;
}

From source file:lu.lippmann.cdb.graph.renderer.CadralEdgeColorTransformer.java

private static Color rangeColor(Color colorMin, Color colorMax, BigDecimal grow, BigDecimal minValue,
        BigDecimal maxValue) {//from  ww  w . j a v a2s  .c o  m
    BigDecimal colorValue = grow;
    if (colorValue == null) {
        return Color.LIGHT_GRAY;
    }

    if (maxValue.compareTo(minValue) < 0) {
        return rangeColor(colorMin, colorMax, grow, maxValue, minValue);
    } else {
        int rMax = colorMax.getRed();
        int gMax = colorMax.getGreen();
        int bMax = colorMax.getBlue();

        double color = 0.0;

        color = 255.0
                - grow.subtract(minValue).doubleValue() * 255.0 / maxValue.subtract(minValue).doubleValue();

        int r = rMax + (int) ((255 - rMax) * color / 255.0);
        int g = gMax + (int) ((255 - gMax) * color / 255.0);
        int b = bMax + (int) ((255 - bMax) * color / 255.0);

        if (r > 192 && g > 192 && b > 192)
            return Color.LIGHT_GRAY;

        return new Color(r, g, b);
    }

}

From source file:cn.z.Ocr5.java

public static int getColorBright(int colorInt) {
    Color color = new Color(colorInt);
    return color.getRed() + color.getGreen() + color.getBlue();
}

From source file:org.pgptool.gui.ui.tools.UiUtils.java

public static void setLookAndFeel() {
    // NOTE: We doing it this way to prevent dead=locks that is sometimes
    // happens if do it in main thread
    Edt.invokeOnEdtAndWait(new Runnable() {
        @Override//w ww  .  jav  a2s.co  m
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                fixCheckBoxMenuItemForeground();
                fixFontSize();
            } catch (Throwable t) {
                log.error("Failed to set L&F", t);
            }
        }

        /**
         * In some cases (depends on OS theme) check menu item foreground is same as
         * bacground - thus it;'s invisible when cheked
         */
        private void fixCheckBoxMenuItemForeground() {
            UIDefaults defaults = UIManager.getDefaults();
            Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground");
            Color foreground = defaults.getColor("CheckBoxMenuItem.foreground");
            Color background = defaults.getColor("CheckBoxMenuItem.background");
            if (colorsDiffPercentage(selectionForeground, background) < 10) {
                // TODO: That doesn't actually affect defaults. Need to find out how to fix it
                defaults.put("CheckBoxMenuItem.selectionForeground", foreground);
            }
        }

        private int colorsDiffPercentage(Color c1, Color c2) {
            int diffRed = Math.abs(c1.getRed() - c2.getRed());
            int diffGreen = Math.abs(c1.getGreen() - c2.getGreen());
            int diffBlue = Math.abs(c1.getBlue() - c2.getBlue());

            float pctDiffRed = (float) diffRed / 255;
            float pctDiffGreen = (float) diffGreen / 255;
            float pctDiffBlue = (float) diffBlue / 255;

            return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100);
        }

        private void fixFontSize() {
            if (isJreHandlesScaling()) {
                log.info("JRE handles font scaling, won't change it");
                return;
            }
            log.info("JRE doesnt't seem to support font scaling");

            Toolkit toolkit = Toolkit.getDefaultToolkit();
            int dpi = toolkit.getScreenResolution();
            if (dpi == 96) {
                if (log.isDebugEnabled()) {
                    Font font = UIManager.getDefaults().getFont("TextField.font");
                    String current = font != null ? Integer.toString(font.getSize()) : "unknown";
                    log.debug(
                            "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be "
                                    + current);
                }
                return;
            }
            int targetFontSize = 12 * dpi / 96;
            log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize);
            setDefaultSize(targetFontSize);
        }

        private boolean isJreHandlesScaling() {
            try {
                JreVersion noNeedToScaleForVer = JreVersion.parseString("9");
                String jreVersionStr = System.getProperty("java.version");
                if (jreVersionStr != null) {
                    JreVersion curVersion = JreVersion.parseString(jreVersionStr);
                    if (noNeedToScaleForVer.compareTo(curVersion) <= 0) {
                        return true;
                    }
                }

                return false;
            } catch (Throwable t) {
                log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: "
                        + System.getProperty("java.version"), t);
                return true;
            }
        }

        public void setDefaultSize(int size) {
            Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
            Object[] keys = keySet.toArray(new Object[keySet.size()]);
            for (Object key : keys) {
                if (key != null && key.toString().toLowerCase().contains("font")) {
                    Font font = UIManager.getDefaults().getFont(key);
                    if (font != null) {
                        Font changedFont = font.deriveFont((float) size);
                        UIManager.put(key, changedFont);
                        Font doubleCheck = UIManager.getDefaults().getFont(key);
                        log.debug("Font size changed for " + key + ". From " + font.getSize() + " to "
                                + doubleCheck.getSize());
                    }
                }
            }
        }
    });
    log.info("L&F set");
}

From source file:cn.z.Ocr5.java

public static int isBlack(int colorInt, int blackThreshold) {
    final Color color = new Color(colorInt);
    if (color.getRed() + color.getGreen() + color.getBlue() <= blackThreshold) {
        return 1;
    }//from  w ww  .  j  a v  a2 s  .  c  o m
    return 0;
}

From source file:cn.z.Ocr5.java

public static int isWhite(int colorInt, int whiteThreshold) {
    final Color color = new Color(colorInt);
    if (color.getRed() + color.getGreen() + color.getBlue() > whiteThreshold) {
        return 1;
    }/*from  w ww  .  j  a v a  2 s  .co m*/
    return 0;
}

From source file:imageprocessingproject.ImageHistogram.java

public static BufferedImage normalizeImage(BufferedImage image) {
    int height = image.getHeight();
    int width = image.getWidth();

    int r, g, b, minr = 255, ming = 255, minb = 255, maxr = 0, maxg = 0, maxb = 0;
    Color c;

    BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            if (minr > c.getRed()) {
                minr = c.getRed();/*w  w w . j a  v a 2 s . c om*/
            }
            if (ming > c.getGreen()) {
                ming = c.getGreen();
            }
            if (minb > c.getBlue()) {
                minb = c.getBlue();
            }
            if (maxr < c.getRed()) {
                maxr = c.getRed();
            }
            if (maxg < c.getGreen()) {
                maxg = c.getGreen();
            }
            if (maxb < c.getBlue()) {
                maxb = c.getBlue();
            }
        }
    }

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            r = (int) ((c.getRed() - minr) * 255 / (maxr - minr));
            g = (int) ((c.getGreen() - ming) * 255 / (maxg - ming));
            b = (int) ((c.getBlue() - minb) * 255 / (maxb - minb));
            tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB());
        }
    }

    return tempImage;
}