Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

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

Prototype

public Color(int rgb) 

Source Link

Document

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

Usage

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(File input) throws IOException {
    BufferedImage image;//from   w  w  w.  ja  v a  2  s . c o  m
    int width, height;

    // File input = new File(ip);
    image = ImageIO.read(input);
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }
    // HSV2File(hsvImage,width,height); debugging code removed      
    return hsvImage;
}

From source file:PCATestApplet.java

public void init() {

    /*// w  ww  .  j a  v a 2  s .com
    // Data definition
    int n = 10;
    //read params to create these
    double[][] datas1 = new double[n][3];
    double[][] datas2 = new double[n][3];
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) { // 3 == set the x,y,z...goto next of the 10
       datas1[i][j] = Math.random();
       datas2[i][j] = Math.random();
    }
    }
    */

    Plot3DPanel plotpanel = new Plot3DPanel();
    plotpanel.setAxeLabel(0, "PC1");
    plotpanel.setAxeLabel(1, "PC2");
    plotpanel.setAxeLabel(2, "PC3");
    plotpanel.addLegend("SOUTH");

    String totalPts = getParameter("totalPts");
    String totalGps = getParameter("totalGps");
    //groupLabel_x
    //groupCount_x
    //pt_x_x (group#_pt#)

    for (int i = 0; i < Integer.parseInt(totalGps); i++) {
        String thisGrpLabel = getParameter("groupLabel_" + i);
        String thisGrpCount = getParameter("groupCount_" + i);
        String thisGrpColor = getParameter("groupColor_" + i);
        double[][] lumpData = new double[Integer.parseInt(thisGrpCount)][3];

        for (int t = 0; t < Integer.parseInt(thisGrpCount); t++) {
            String v = getParameter("pt_" + i + "_" + t);
            String[] xyz = StringUtils.split(v, ",");
            for (int j = 0; j < 3; j++) {
                lumpData[t][j] = Double.valueOf(xyz[j]).doubleValue();
            }
        }

        //plotpanel.addScatterPlot(thisGrpLabel, lumpData);
        plotpanel.addScatterPlot(thisGrpLabel, new Color(Integer.parseInt(thisGrpColor)), lumpData);
        lumpData = null;
    }

    /*
    //lump data example
    double[][] lumpData = new double[Integer.parseInt(totalPts)][3];
    for(int i=0; i<Integer.parseInt(totalPts); i++){
    String v = getParameter("pt_"+i);
    String[] xyz = StringUtils.split(v, ",");
    for(int j=0; j<3; j++){
       lumpData[i][j] = Double.valueOf(xyz[j]);
    }
    }
    */

    // PlotPanel construction
    //Plot3DPanel plotpanel = new Plot3DPanel();
    //plotpanel.setAxeLabel(0, "PC1");
    //plotpanel.setAxeLabel(1, "PC2");
    //plotpanel.setAxeLabel(2, "PC3");
    //plotpanel.addLegend("SOUTH");

    // Data plots addition
    //plotpanel.addScatterPlot("lump data", lumpData);

    //plotpanel.addScatterPlot(totalPts + " datas1", datas1);
    //plotpanel.addScatterPlot("datas2", datas2);
    //plotpanel.addBarPlot("datas2", datas2);

    // include plot in applet
    add(plotpanel);
}

From source file:lisong_mechlab.view.graphs.WeaponColouredDrawingSupplier.java

private Color colorShift(Color aColour, int aMax, int aCurr) {
    float hsb[] = new float[3];
    Color.RGBtoHSB(aColour.getRed(), aColour.getGreen(), aColour.getBlue(), hsb);

    float blend = aMax == 1 ? 1.0f : (float) aCurr / (aMax - 1);
    float range_min = 0.55f;
    float range_max = 1.0f;
    float saturation = (range_max - range_min) * blend + range_min;

    hsb[1] *= saturation;/*from  ww  w  . j  av a2s .  co m*/
    hsb[2] *= saturation;

    return new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.boxcharts.SimpleBox.java

public JFreeChart createChart(DatasetMap datasetMap) {

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) datasetMap.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(name, categoryLabel, valueLabel, dataset, false);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);/*from ww w  .  j a v a 2 s  .  com*/
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer) plot.getRenderer();
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(new Color(Integer.decode("#c0c0c0").intValue()));
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    renderer.setFillBox(true);
    renderer.setArtifactPaint(Color.BLACK);
    renderer.setSeriesPaint(0, new Color(Integer.decode("#0000FF").intValue()));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(min, max);

    return chart;
}

From source file:simulador.controle.GraficoCategorias.java

private static void renderizarGrafico(JFreeChart grafico) {

    if (DEBUG) {// w  ww .  j  a  v  a  2  s . co m
        System.out.println("GraficoRadiais.renderizarGrafico");
    }

    XYLineAndShapeRenderer renderizador = new XYLineAndShapeRenderer();
    int qtdSeries, aux;

    qtdSeries = grafico.getXYPlot().getDataset().getSeriesCount();
    //aux = (Color.WHITE.getRGB() - Color.BLACK.getRGB())/qtdSeries;   
    aux = 360 / qtdSeries;

    //System.out.println("aux = "+aux);
    for (int i = 0; i < qtdSeries; i++) {
        renderizador.setSeriesPaint(i, new Color(Color.HSBtoRGB((aux * i) / 360.0f, 1.0f, 1.0f)));
        renderizador.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    //renderizador.setSeriesLinesVisible(0, false);

    grafico.getXYPlot().setRenderer(renderizador);

}

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 av  a 2 s .c  o  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:herramientas.Ecualizacion_histograma.java

private void cogerDatos() {
    //        size = img.getWidth() * img.getHeight();
    datos = new int[256];

    //Inicializar datos a 0.
    for (int i = 0; i < 256; i++) {
        datos[i] = 0;//from w w w.j av  a2s.  c  om
    }

    //Obtener datos de nivel de color.
    for (int i = 0; i < img.getWidth(); i++) {
        for (int j = 0; j < img.getHeight(); j++) {
            Color c = new Color(img.getRGB(i, j));

            datos[c.getRed()] += 1;
            //                System.out.println(i + "," + j);
            //                System.out.println(img.getRGB(i, j));
            //                System.out.println(c);
        }
    }
    datos[0] -= fondo;
    System.out.println("ec fondo" + fondo);

}

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;//w ww.  ja  v  a 2  s . c om
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:com.floreantpos.model.MenuCategory.java

@XmlTransient
public Color getButtonColor() {
    if (buttonColor != null) {
        return buttonColor;
    }//from   ww  w .j  av a2  s  .c  o  m

    if (getButtonColorCode() == null || getButtonColorCode() == 0) {
        return null;
    }

    return buttonColor = new Color(getButtonColorCode());
}

From source file:net.dv8tion.jda.core.handle.GuildRoleUpdateHandler.java

@Override
protected Long handleInternally(JSONObject content) {
    final long guildId = content.getLong("guild_id");
    if (api.getGuildLock().isLocked(guildId))
        return guildId;

    JSONObject rolejson = content.getJSONObject("role");
    GuildImpl guild = (GuildImpl) api.getGuildMap().get(guildId);
    if (guild == null) {
        api.getEventCache().cache(EventCache.Type.GUILD, guildId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("Received a Role Update for a Guild that is not yet cached: " + content);
        return null;
    }/*from  ww  w . ja v a  2s  . c om*/

    final long roleId = rolejson.getLong("id");
    RoleImpl role = (RoleImpl) guild.getRolesMap().get(roleId);
    if (role == null) {
        api.getEventCache().cache(EventCache.Type.ROLE, roleId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("Received a Role Update for Role that is not yet cached: " + content);
        return null;
    }

    String name = rolejson.getString("name");
    Color color = rolejson.getInt("color") != 0 ? new Color(rolejson.getInt("color")) : null;
    int position = rolejson.getInt("position");
    long permissions = rolejson.getLong("permissions");
    boolean hoisted = rolejson.getBoolean("hoist");
    boolean mentionable = rolejson.getBoolean("mentionable");

    if (!Objects.equals(name, role.getName())) {
        String oldName = role.getName();
        role.setName(name);
        api.getEventManager().handle(new RoleUpdateNameEvent(api, responseNumber, role, oldName));
    }
    if (!Objects.equals(color, role.getColor())) {
        Color oldColor = role.getColor();
        role.setColor(color);
        api.getEventManager().handle(new RoleUpdateColorEvent(api, responseNumber, role, oldColor));
    }
    if (!Objects.equals(position, role.getPositionRaw())) {
        int oldPosition = role.getPosition();
        int oldPositionRaw = role.getPositionRaw();
        role.setRawPosition(position);
        api.getEventManager()
                .handle(new RoleUpdatePositionEvent(api, responseNumber, role, oldPosition, oldPositionRaw));
    }
    if (!Objects.equals(permissions, role.getPermissionsRaw())) {
        long oldPermissionsRaw = role.getPermissionsRaw();
        role.setRawPermissions(permissions);
        api.getEventManager()
                .handle(new RoleUpdatePermissionsEvent(api, responseNumber, role, oldPermissionsRaw));
    }

    if (hoisted != role.isHoisted()) {
        boolean wasHoisted = role.isHoisted();
        role.setHoisted(hoisted);
        api.getEventManager().handle(new RoleUpdateHoistedEvent(api, responseNumber, role, wasHoisted));
    }
    if (mentionable != role.isMentionable()) {
        boolean wasMentionable = role.isMentionable();
        role.setMentionable(mentionable);
        api.getEventManager().handle(new RoleUpdateMentionableEvent(api, responseNumber, role, wasMentionable));
    }
    return null;
}