List of usage examples for java.awt Color getRGB
public int getRGB()
From source file:org.alder.fotobuchconvert.scribus.ColorManager.java
private String color2rgbStr(Color color) { String s = Integer.toHexString(color.getRGB() & 0xFFFFFF); while (s.length() < 6) s = "0" + s; String rgbCode = "#" + s; return rgbCode; }
From source file:it.units.malelab.ege.util.DUMapper.java
private static void saveImage(String fileName, boolean margin, int scale, double[][]... data) { BufferedImage bi = new BufferedImage(data[0].length * scale, data[0][0].length * scale, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < data[0].length; y++) { for (int x = 0; x < data[0][y].length; x++) { Color color; if (data.length == 1) { color = new Color((float) data[0][y][x], (float) data[0][y][x], (float) data[0][y][x], 1); } else { color = new Color((float) data[0][y][x], (float) data[1][y][x], data.length >= 3 ? (float) data[2][y][x] : 0, data.length >= 4 ? (float) data[3][y][x] : 1); }// w w w .j a va 2 s.c o m if (scale == 1) { bi.setRGB(y, x, color.getRGB()); } else { for (int ix = x * scale + (margin ? 1 : 0); ix < (x + 1) * scale - (margin ? 1 : 0); ix++) { for (int iy = y * scale + (margin ? 1 : 0); iy < (y + 1) * scale - (margin ? 1 : 0); iy++) { bi.setRGB(iy, ix, color.getRGB()); } } } } } try { ImageIO.write(bi, "PNG", new File(fileName)); } catch (IOException ex) { System.err.printf("Cannot save file \"%s\": %s", fileName, ex.getMessage()); } }
From source file:com.github.orangefoundry.gorender.controllers.ImageRenderController.java
private byte[] renderPlaceHolder(String size, String colour) throws IOException { if (size == null || size.isEmpty()) { size = Default.SIZE.getValue();//from w w w .jav a 2 s . c om } if (colour == null || colour.isEmpty()) { colour = Default.COLOUR.getValue(); } String[] sizes = new String[2]; if (size != null && !size.isEmpty()) { sizes = size.toLowerCase().split("x"); } int width = Integer.parseInt(sizes[0]), height = Integer.parseInt(sizes[1]); final ColourToAWTColour colourToAWTColour = new ColourToAWTColour(); Color myColour = colourToAWTColour.getColour(colour); int rgb = myColour.getRGB(); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] data = new int[width * height]; int i = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { data[i++] = rgb; } } bi.setRGB(0, 0, width, height, data, 0, width); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ImageIO.write(bi, "png", bao); return bao.toByteArray(); }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static BufferedImage getBufferedIm(int[][][] rgbValues) { int ImW = rgbValues[0].length; int ImH = rgbValues[0][0].length; BufferedImage ImageOut = new BufferedImage(ImW, ImH, 5); // 5 for PNG; Color tmpColor; for (int ii = 0; ii < ImW; ii++) { for (int jj = 0; jj < ImH; jj++) { tmpColor = new Color((int) Math.round(rgbValues[0][ii][jj]), (int) Math.round(rgbValues[1][ii][jj]), (int) Math.round(rgbValues[2][ii][jj])); ImageOut.setRGB(ii, jj, tmpColor.getRGB()); }/*from w w w . j av a 2 s . co m*/ } return ImageOut; }
From source file:org.eclipse.smarthome.ui.webapp.internal.render.ColorpickerRenderer.java
/** * {@inheritDoc}/*from w w w . j a v a 2s . c o m*/ */ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException { Colorpicker cp = (Colorpicker) w; String snippetName = "colorpicker"; String snippet = getSnippet(snippetName); // set the default send-update frequency to 200ms String frequency = cp.getFrequency() == 0 ? "200" : Integer.toString(cp.getFrequency()); // get RGB hex value State state = itemUIRegistry.getState(cp); String hexValue = "#ffffff"; if (state instanceof HSBType) { HSBType hsbState = (HSBType) state; Color color = hsbState.toColor(); hexValue = "#" + Integer.toHexString(color.getRGB()).substring(2); } String label = getLabel(cp); String purelabel = label; if (label.contains("<span>")) { purelabel = purelabel.substring(0, label.indexOf("<span>")); } snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(cp)); snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(cp))); snippet = StringUtils.replace(snippet, "%item%", w.getItem()); snippet = StringUtils.replace(snippet, "%label%", label); snippet = StringUtils.replace(snippet, "%purelabel%", purelabel); snippet = StringUtils.replace(snippet, "%state%", hexValue); snippet = StringUtils.replace(snippet, "%frequency%", frequency); snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME); String style = ""; String color = itemUIRegistry.getLabelColor(w); if (color != null) { style = "color:" + color; } snippet = StringUtils.replace(snippet, "%labelstyle%", style); style = ""; color = itemUIRegistry.getValueColor(w); if (color != null) { style = "color:" + color; } snippet = StringUtils.replace(snippet, "%valuestyle%", style); sb.append(snippet); return null; }
From source file:pl.otros.logview.gui.message.html.ExportToHtml.java
protected String colorToHex(Color c) { return "#" + Integer.toHexString(c.getRGB()).substring(2); }
From source file:net.sf.dynamicreports.googlecharts.jasper.geomap.GeoMapElementHtmlHandler.java
private String getColorString(Color color) { int colorMask = Integer.parseInt("FFFFFF", 16); String hex = Integer.toHexString(color.getRGB() & colorMask).toUpperCase(); return "0x" + ("000000" + hex).substring(hex.length()); }
From source file:org.stanwood.nwn2.gui.view.UIIconView.java
@Override public void paintUIObject(Graphics g) { int x = getX(); int y = getY(); try {/*from ww w.j a va 2s.c o m*/ BufferedImage img = getIconManager().getIcon(icon.getImg()); int width = getWidth(); int height = getHeight(); if (img.getHeight() != height && img.getWidth() != width) { Image newImg = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics ig = img.getGraphics(); ig.drawImage(newImg, 0, 0, null); } if (icon.getColor() != null) { Color colour = getColor(icon.getColor()); for (int w = 0; w < img.getWidth(); w++) { for (int h = 0; h < img.getHeight(); h++) { Color rgb = ColorUtil.blend(new Color(img.getRGB(w, h)), colour); img.setRGB(w, h, rgb.getRGB()); } } } g.drawImage(img, x, y, null); } catch (Exception e) { log.error(e.getMessage()); drawMissingIcon(x, y, getWidth(), getHeight(), g); } }
From source file:org.rockyroadshub.planner.loader.PropertyLoader.java
public void setProperty(Property property, Object value) { String val; if (value instanceof Color) { Color color = (Color) value; val = String.format("#%08x", color.getRGB()); } else {/*from w ww . java2 s . c om*/ val = (String) value; } plannerProperties.setProperty(property.toString(), val); }
From source file:gov.nih.nci.caintegrator.application.geneexpression.LegendItemWrapper.java
private String c2hex(Color c) { //http://rsb.info.nih.gov/ij/developer/source/index.html 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 & HEX_0XF]; i >>>= 4;//from www . j av a 2 s . c o m } return new String(buf7); }