Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

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

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:gmgen.util.MiscUtilities.java

/** Converts a Color to an 7 byte hex string starting with '#'.
 * @param c/*from  ww w. ja  va 2s.  c  om*/
 * @return String*/
public static String colorToHex(Color c) {
    final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    int i = c.getRGB();
    char[] buf7 = new char[7];
    buf7[0] = '#';
    for (int pos = 6; pos >= 1; pos--) {
        buf7[pos] = hexDigits[i & 0xf];
        i >>>= 4;
    }
    return new String(buf7);
}

From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java

private static BufferedImage changeColor(BufferedImage image, Color mask, Color replacement) {
    BufferedImage destImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = destImage.createGraphics();
    g.drawImage(image, null, 0, 0);/*from w  w  w .jav a2s.c om*/
    g.dispose();

    for (int i = 0; i < destImage.getWidth(); i++) {
        for (int j = 0; j < destImage.getHeight(); j++) {

            int destRGB = destImage.getRGB(i, j);

            if (matches(mask.getRGB(), destRGB)) {
                int rgbnew = getNewPixelRGB(replacement.getRGB(), destRGB);
                destImage.setRGB(i, j, rgbnew);
            }
        }
    }

    return destImage;
}

From source file:nl.b3p.imagetool.ImageTool.java

/**
 *
 *//*from   w w  w . j ava 2s .  c om*/
public static BufferedImage changeColor(BufferedImage im, Color color, Color newColor) {
    for (int x = 0; x < im.getWidth(); x++) {
        for (int y = 0; y < im.getHeight(); y++) {
            if (im.getRGB(x, y) == color.getRGB()) {
                im.setRGB(x, y, newColor.getRGB());
            }
        }
    }
    return im;
}

From source file:gov.nih.nci.rembrandt.web.helper.PCAAppletHelper.java

public static String generateParams(String sessionId, String taskId) {
    String htm = "";
    DecimalFormat nf = new DecimalFormat("0.0000");

    try {//w w  w  .ja  v  a  2  s. co  m
        //retrieve the Finding from cache and build the list of PCAData points
        PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache
                .getSessionFinding(sessionId, taskId);

        ArrayList<PrincipalComponentAnalysisDataPoint> pcaData = new ArrayList();

        Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>();
        List<String> sampleIds = new ArrayList();
        Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>();

        List<PCAresultEntry> pcaResults = principalComponentAnalysisFinding.getResultEntries();
        for (PCAresultEntry pcaEntry : pcaResults) {
            sampleIds.add(pcaEntry.getSampleId());
            pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry);
        }

        Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator
                .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors);

        if (validatedSampleResultset != null) {
            String id;
            PCAresultEntry entry;

            for (SampleResultset rs : validatedSampleResultset) {
                id = rs.getBiospecimen().getSpecimenName();
                entry = pcaResultMap.get(id);
                PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id,
                        entry.getPc1(), entry.getPc2(), entry.getPc3());
                String diseaseName = rs.getDisease().getValueObject();
                if (diseaseName != null) {
                    pcaPoint.setDiseaseName(diseaseName);
                } else {
                    pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name());
                }
                GenderDE genderDE = rs.getGenderCode();
                if (genderDE != null) {
                    String gt = genderDE.getValueObject();
                    if (gt != null) {
                        GenderType genderType = GenderType.valueOf(gt);
                        if (genderType != null) {
                            pcaPoint.setGender(genderType);
                        }
                    }
                }
                Long survivalLength = rs.getSurvivalLength();
                if (survivalLength != null) {
                    //survival length is stored in days in the DB so divide by 30 to get the 
                    //approx survival in months
                    double survivalInMonths = survivalLength.doubleValue() / 30.0;
                    pcaPoint.setSurvivalInMonths(survivalInMonths);
                }
                pcaData.add(pcaPoint);
            }
        }

        //make a hashmap
        // [key=group] hold the array of double[][]s
        HashMap<String, ArrayList> hm = new HashMap();

        //now we should have a collection of PCADataPts
        double[][] pts = new double[pcaData.size()][3];
        for (int i = 0; i < pcaData.size(); i++) {
            //just create a large 1 set for now
            //are we breaking groups by gender or disease?
            PrincipalComponentAnalysisDataPoint pd = pcaData.get(i);

            pts[i][0] = pd.getPc1value();
            pts[i][1] = pd.getPc2value();
            pts[i][2] = pd.getPc3value();
            ArrayList<double[]> al;

            try {
                if (hm.containsKey(pd.getDiseaseName())) {
                    //already has it, so add this one
                    al = (ArrayList) hm.get(pd.getDiseaseName());
                } else {
                    al = new ArrayList();
                    hm.put(pd.getDiseaseName(), new ArrayList());
                }
                if (!al.contains(pts[i])) {
                    al.add(pts[i]);
                }
                hm.put(pd.getDiseaseName(), al);
            } catch (Exception e) {
                System.out.print(e.toString());
            }
        }
        int r = hm.size();
        if (r == 1) {
        }
        //hm should now contain a hashmap of all the disease groups

        //generate the param tags
        htm += "<param name=\"key\" value=\"" + taskId + "\" >\n";
        htm += "<param name=\"totalPts\" value=\"" + pts.length + "\" >\n";
        htm += "<param name=\"totalGps\" value=\"" + hm.size() + "\" >\n";
        int ii = 0;
        for (Object k : hm.keySet()) {
            String key = k.toString();
            //for each group

            Color diseaseColor = Color.GRAY;
            if (DiseaseType.valueOf(key) != null) {
                DiseaseType disease = DiseaseType.valueOf(key);
                diseaseColor = disease.getColor();
            }

            ArrayList<double[]> al = hm.get(key);
            htm += "<param name=\"groupLabel_" + ii + "\" value=\"" + key + "\" >\n";
            htm += "<param name=\"groupCount_" + ii + "\" value=\"" + al.size() + "\" >\n";
            htm += "<param name=\"groupColor_" + ii + "\" value=\"" + diseaseColor.getRGB() + "\" >\n";
            int jj = 0;
            for (double[] d : al) {
                String comm = nf.format(d[0]) + "," + nf.format(d[1]) + "," + nf.format(d[2]);
                String h = "<param name=\"pt_" + ii + "_" + jj + "\" value=\"" + comm + "\">\n";
                htm += h;
                jj++;
            }
            ii++;
        }
        /*
         //for bulk rendering
        for(int i=0; i<pts.length; i++)   {
           String comm = String.valueOf(pts[i][0]) + "," +
           String.valueOf(pts[i][1]) + "," +
           String.valueOf(pts[i][2]);
                   
           String h = "<param name=\"pt_"+i+"\" value=\""+ comm +"\">\n";
           //htm += h;
        }
        */

    } //try
    catch (Exception e) {

    }

    return htm;
}

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   ww  w.  ja v a  2s.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:Main.java

/**
 * Converts a color into a string. If the color is equal to one of the defined
 * constant colors, that name is returned instead. Otherwise the color is
 * returned as hex-string.//from  w w w.  j  ava 2s  . c  o  m
 * 
 * @param c
 *          the color.
 * @return the string for this color.
 */
public static String colorToString(final Color c) {
    try {
        final Field[] fields = Color.class.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field f = fields[i];
            if (Modifier.isPublic(f.getModifiers()) && Modifier.isFinal(f.getModifiers())
                    && Modifier.isStatic(f.getModifiers())) {
                final String name = f.getName();
                final Object oColor = f.get(null);
                if (oColor instanceof Color) {
                    if (c.equals(oColor)) {
                        return name;
                    }
                }
            }
        }
    } catch (Exception e) {
        //
    }

    // no defined constant color, so this must be a user defined color
    final String color = Integer.toHexString(c.getRGB() & 0x00ffffff);
    final StringBuffer retval = new StringBuffer(7);
    retval.append("#");

    final int fillUp = 6 - color.length();
    for (int i = 0; i < fillUp; i++) {
        retval.append("0");
    }

    retval.append(color);
    return retval.toString();
}

From source file:phex.gui.common.PhexColors.java

/**
 * Colors get usually update when a UI update is performed.
 *//* w  w  w. j  a  va  2 s.c  om*/
public static void updateColors() {
    Color activeCaptionBorderColor = UIManager.getColor("activeCaptionBorder");
    Color infoColor = UIManager.getColor("info");

    if ((SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS)
            && UIManager.getLookAndFeel().isNativeLookAndFeel()) {
        // in case this is native LAF we use our special orange color set
        // this is done because the standard ui colors we use for other LAF
        // just look so bad and ugly on Mac OSX.
        activatePhexColors();
    } else if (infoColor == null || activeCaptionBorderColor == null) {
        // to prevent errors on LAF with some missing UI Colors we use
        // the Phex color set on this LAF.
        // (occures on Linux with GTK LAF)
        activatePhexColors();
    } else {
        boxPanelBorderColor = GUIUtils.darkerColor(activeCaptionBorderColor, 0.8);
        boxPanelBackground = new Color(infoColor.getRGB());
        boxHeaderBackground = GUIUtils.darkerColor(activeCaptionBorderColor, 0.9);
        boxHeaderGradientFrom = new Color(activeCaptionBorderColor.getRGB());
        boxHeaderGradientTo = GUIUtils.brighterColor(infoColor, 0.8);
        linkLabelRolloverForeground = GUIUtils.darkerColor(activeCaptionBorderColor, 0.8);

        scopeProgressBarBackground = UIManager.getColor("window");
        scopeProgressBarForeground = UIManager.getColor("ProgressBar.foreground");

        finishedScopeProgressBarForeground = scopeProgressBarForeground;

        // give it a touch of red and saturation
        unverifiedScopeProgressBarForeground = new Color(0xf04656);

        // use a lighter color
        blockedScopeProgressBarForeground = GUIUtils.brighterColor(infoColor, 0.7);
    }
}

From source file:RasterImageTest.java

/**
 * Makes the Mandelbrot image./*from   w  w  w  . j ava 2 s.c om*/
 * @param width the width
 * @parah height the height
 * @return the image
 */
public BufferedImage makeMandelbrot(int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    WritableRaster raster = image.getRaster();
    ColorModel model = image.getColorModel();

    Color fractalColor = Color.red;
    int argb = fractalColor.getRGB();
    Object colorData = model.getDataElements(argb, null);

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            double a = XMIN + i * (XMAX - XMIN) / width;
            double b = YMIN + j * (YMAX - YMIN) / height;
            if (!escapesToInfinity(a, b))
                raster.setDataElements(i, j, colorData);
        }
    return image;
}

From source file:SystemColorChooserPanel.java

private int findColorPosition(Color color) {
    int position = colors.length - 1;

    int colorRGB = color.getRGB();
    for (int i = 0, n = colors.length; i < n; i++) {
        if ((colors[i] != null) && (colorRGB == colors[i].getRGB())) {
            position = i;/*from www  .j  ava2  s.  c o  m*/
            break;
        }
    }
    return position;
}

From source file:MainClass.java

private int findColorPosition(Color color) {
    int position = colors.length - 1;
    int colorRGB = color.getRGB();
    for (int i = 0, n = colors.length; i < n; i++) {
        if ((colors[i] != null) && (colorRGB == colors[i].getRGB())) {
            position = i;//w w  w .jav a2s. com
            break;
        }
    }
    return position;
}