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:it.units.malelab.ege.util.DUMapper.java

private static void modifyMap(String fileName, float bins) throws IOException {
    Color[][] colorMap = new Color[3][];
    colorMap[0] = new Color[] { fromCode("000000"), fromCode("b36600"), fromCode("f3b300") };
    colorMap[1] = new Color[] { fromCode("376387"), fromCode("b3b3b3"), fromCode("f3e6b3") };
    colorMap[2] = new Color[] { fromCode("509dc2"), fromCode("b4d3e1"), fromCode("f3f3f3") };
    BufferedImage inImage = ImageIO.read(new File(fileName));
    BufferedImage outRGDImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    BufferedImage outCMImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    for (int x = 0; x < inImage.getWidth(); x++) {
        for (int y = 0; y < inImage.getHeight(); y++) {
            Color inColor = new Color(inImage.getRGB(x, y));
            Color outColor = new Color(
                    Math.min((float) Math.floor((float) inColor.getRed() / 255f * bins) / (bins - 1), 1f),
                    Math.min((float) Math.floor((float) inColor.getGreen() / 255f * bins) / (bins - 1), 1f), 0);
            outRGDImage.setRGB(x, y, outColor.getRGB());
            int cmRIndex = (int) Math.min((int) Math.floor((float) inColor.getRed() / 255f * 3), 2);
            int cmGIndex = (int) Math.min((int) Math.floor((float) inColor.getGreen() / 255f * 3), 2);
            outColor = colorMap[cmRIndex][cmGIndex];
            outCMImage.setRGB(x, y, outColor.getRGB());
        }//from  w w w  .  j  a  v a2 s  .c o  m
    }
    ImageIO.write(outRGDImage, "PNG",
            new File(fileName.replace(".png", String.format(".rgbdisc%d.png", (int) bins))));
    ImageIO.write(outCMImage, "PNG", new File(fileName.replace(".png", ".cm.png")));
}

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

/**
  * Returns the hex version of a Color object.  
  * Output is red, green, blue.//  w  w w. java  2 s  .c o 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: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  va2s . co 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()));
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java

private static Color mixColors(Color c1, double w1, Color c2, double w2) {

    if (w1 == 0.0) {
        return c2;
    }//  w w w .jav a 2 s .  com

    if (w2 == 0.0) {
        return c1;
    }

    double wa1 = FastMath.abs(w1);
    double wa2 = FastMath.abs(w2);

    double total = wa1 + wa2;

    double t1 = wa1 / total;
    double t2 = wa2 / total;

    if (t1 < 0.1) {
        t1 = 0.1;
        t2 = 0.8;
    }

    if (t2 < 0.1) {
        t1 = 0.8;
        t2 = 0.1;
    }

    int red = (int) (t1 * (double) c1.getRed() + t2 * (double) c2.getRed());
    int green = (int) (t1 * (double) c1.getGreen() + t2 * (double) c2.getGreen());
    int blue = (int) (t1 * (double) c1.getBlue() + t2 * (double) c2.getBlue());

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

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

public static ByteBuffer indexed2RGBA8888(ByteBuffer indexedPixels, Color[] palette) {
    Color color;
    ByteBuffer buf = ByteBuffer.allocateDirect(indexedPixels.capacity() * 4);
    final int cap = indexedPixels.capacity();
    for (int i = 0; i < cap; i++) {
        color = palette[(indexedPixels.get() & 0xFF)];
        buf.put((byte) color.getRed());
        buf.put((byte) color.getGreen());
        buf.put((byte) color.getBlue());
        buf.put((byte) color.getAlpha());
    } // end for(i)
    buf.clear();// Rewind
    return buf;/*w w w .j  a va  2 s  .co  m*/
}

From source file:org.ut.biolab.medsavant.shared.util.MiscUtils.java

/**
 * Blend two colours, in the given proportions. Resulting alpha is always
 * 1.0./*ww w . j a  v a2 s  .  c  om*/
 *
 * @param col1 the first colour
 * @param col2 the second colour
 * @param weight1 the weight given to col1 (from 0.0-1.0)
 */
public static Color blend(Color col1, Color col2, float weight1) {

    float weight2 = (1.0F - weight1) / 255;
    weight1 /= 255;

    // This constructor expects values from 0.0F to 1.0F, so weights have to be scaled appropriately.
    return new Color(col1.getRed() * weight1 + col2.getRed() * weight2,
            col1.getGreen() * weight1 + col2.getGreen() * weight2,
            col1.getBlue() * weight1 + col2.getBlue() * weight2);
}

From source file:mx.itesm.web2mexadl.cluster.ClusterAnalyzer.java

/**
 * Generate a random color, to identify Clusters. Based on:
 * http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate
 * -an-aesthetically-pleasing-color-palette
 * // w ww . ja v  a 2  s .co  m
 * @return
 */
private static Color getRandomColor() {
    int red;
    int blue;
    int green;
    Random random;
    Color mixColor;
    Color returnValue;

    // Base color (white)
    mixColor = new Color(255, 255, 255);
    random = new Random();
    red = random.nextInt(256);
    green = random.nextInt(256);
    blue = random.nextInt(256);

    // Mix new color with base one
    red = (red + mixColor.getRed()) / 2;
    green = (green + mixColor.getGreen()) / 2;
    blue = (blue + mixColor.getBlue()) / 2;

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

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Convert a color object to a hex string
 **//*from ww w .j  av a2 s.  c om*/
public static String colorToHex(Color colorCode) {
    int r = colorCode.getRed();
    int g = colorCode.getGreen();
    int b = colorCode.getBlue();

    return toHex(r) + toHex(g) + toHex(b);
}

From source file:main.java.whiteSocket.Bloop.java

public static boolean isMarker(Color x) {

    int brightness = (int) (0.2126 * x.getRed() + 0.7152 * x.getGreen() + 0.0722 * x.getBlue());

    if (brightness < brightThreshold)
        return true;
    else//from ww w  .  j av  a2s.c  om
        return false;

}

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

/**
 * Reads background-color from bl and writes it to rtfAttr.
 *
 * @param bpb the CommonBorderPaddingBackground from which the properties are read
 * @param rtfAttr the RtfAttributes object the attributes are written to
 *///www  .j  av a 2 s . c o  m
private static void attrBackgroundColor(CommonBorderPaddingBackground bpb, RtfAttributes rtfAttr) {
    Color fopValue = bpb.backgroundColor;
    int rtfColor = 0;
    /* FOP uses a default background color of "transparent", which is
       actually a transparent black, which is generally not suitable as a
       default here. Changing FOP's default to "white" causes problems in
       PDF output, so we will look for the default here & change it to
       "auto". */
    if ((fopValue == null) || ((fopValue.getRed() == 0) && (fopValue.getGreen() == 0)
            && (fopValue.getBlue() == 0) && (fopValue.getAlpha() == 0))) {
        return;
    } else {
        rtfColor = convertFOPColorToRTF(fopValue);
    }

    rtfAttr.set(RtfText.ATTR_BACKGROUND_COLOR, rtfColor);
}