Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

In this page you can find the example usage for java.awt Color getBlue.

Prototype

public int getBlue() 

Source Link

Document

Returns the blue component in the range 0-255 in the default sRGB space.

Usage

From source file:com.el.ecom.utils.ImageUtils.java

/**
 * ????/*from  ww w .jav  a  2s. c  om*/
 * 
 * @param color 
 * @return ???
 */
private static String toHexEncoding(Color color) {
    Assert.notNull(color);

    String R, G, B;
    StringBuilder result = new StringBuilder();
    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;
    result.append("#").append(R).append(G).append(B);
    return result.toString();
}

From source file:org.jtrfp.trcl.core.Texture.java

private static VectorList colorVL(Color c) {
    final double[] color = new double[] { c.getRed() / 255., c.getGreen() / 255., c.getBlue() / 255.,
            c.getAlpha() / 255. };/*from  w  ww . j a  va2s.c  o  m*/

    return new VectorList() {
        @Override
        public int getNumVectors() {
            return 1;
        }

        @Override
        public int getNumComponentsPerVector() {
            return 4;
        }

        @Override
        public double componentAt(int vectorIndex, int componentIndex) {
            return color[componentIndex];
        }

        @Override
        public void setComponentAt(int vectorIndex, int componentIndex, double value) {
            throw new RuntimeException(
                    "Static palette created by Texture(Color c, TR tr) cannot be written to.");
        }
    };
}

From source file:com.netsteadfast.greenstep.util.SimpleUtils.java

public static int[] getColorRGB2(String color) throws Exception {
    if (StringUtils.isEmpty(color) || color.length() != 7) {
        return new int[] { 0, 0, 0 };
    }// w  w  w.  j  a v a2s  . co  m
    Color c = Color.decode(color);
    return new int[] { c.getRed(), c.getGreen(), c.getBlue() };
}

From source file:org.apache.fop.render.rtf.TextAttributesConverter.java

/**
 * Converts a FOP ColorType to the integer pointing into the RTF color table
 * @param fopColor the ColorType object to be converted
 * @return integer pointing into the RTF color table
 *///from  w w w .j ava 2 s.c om
public static int convertFOPColorToRTF(Color fopColor) {
    // TODO: This code is duplicated in FOPRtfAttributesConverter
    int redComponent = fopColor.getRed();
    int greenComponent = fopColor.getGreen();
    int blueComponent = fopColor.getBlue();
    return RtfColorTable.getInstance().getColorNumber(redComponent, greenComponent, blueComponent).intValue();
}

From source file:canreg.client.analysis.Tools.java

public static Color darken(Color color) {
    return new Color((int) Math.floor(color.getRed() * .9), (int) Math.floor(color.getGreen() * .9),
            (int) Math.floor(color.getBlue() * .9));
}

From source file:org.apache.fop.render.rtf.TextAttributesConverter.java

private static void attrFontColor(Color colorType, RtfAttributes rtfAttr) {
    // Cell background color
    if (colorType != null) {
        if (colorType.getAlpha() != 0 || colorType.getRed() != 0 || colorType.getGreen() != 0
                || colorType.getBlue() != 0) {
            rtfAttr.set(RtfText.ATTR_FONT_COLOR, convertFOPColorToRTF(colorType));
        }/*from  www  . ja  v  a  2s  . co  m*/
    }
}

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

/**
  * Returns the hex version of a Color object.  
  * Output is red, green, blue.//from w  w w. j  av  a2  s.c  om
  * 
  * @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 v a 2s  .  co m*/

            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: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 end) {
    final float[][] colors = new float[][] {
            { start.getRed() / 255f, start.getGreen() / 255f, start.getBlue() / 255f, start.getAlpha() / 255f },
            { end.getRed() / 255f, end.getGreen() / 255f, end.getBlue() / 255f, end.getAlpha() / 255f } };
    final float[] limits = new float[] { 0, 1 };
    final LookupPaintScale lut = new LookupPaintScale(vmin, vmax, start);
    float val;
    float r, g, b, a;
    for (int j = 0; j < ncol; j++) {
        val = j / (ncol - 0.99f);
        final int i = 0;
        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));
    }/*ww  w . jav a  2  s.c o  m*/
    return lut;
}

From source file:lucee.runtime.tag.VideoPlayerJW.java

private static String format(String prefix, Color color) {
    return prefix + toHex(color.getRed()) + toHex(color.getGreen()) + toHex(color.getBlue());
}