List of usage examples for java.awt.image BufferedImage TYPE_INT_ARGB
int TYPE_INT_ARGB
To view the source code for java.awt.image BufferedImage TYPE_INT_ARGB.
Click Source Link
From source file:net.geoprism.dashboard.DashboardMap.java
/** * Generate an image replicating the users map in the browser. * /*w w w . j a va2 s .co m*/ * @outFileFormat - Allowed types (png, gif, jpg, bmp) * @mapBounds - JSON constructed as {"bottom":"VALUE", "top":"VALUE", "left":"VALUE", "right":"VALUE"} * @mapSize - JSON constructed as {"width":"VALUE", "height":"VALUE"} * @activeBaseMap = JSON constructed as {"LAYER_SOURCE_TYPE":"VALUE"} */ @Override public InputStream generateMapImageExport(String outFileFormat, String mapBounds, String mapSize, String activeBaseMap) { InputStream inStream = null; int width; int height; // Get dimensions of the map window (<div>) try { JSONObject mapSizeObj = new JSONObject(mapSize); width = mapSizeObj.getInt("width"); height = mapSizeObj.getInt("height"); } catch (JSONException e) { String error = "Could not parse map size."; throw new ProgrammingErrorException(error, e); } // Setup the base canvas to which we will add layers and map elements BufferedImage base = null; Graphics mapBaseGraphic = null; try { if (outFileFormat.toLowerCase().equals("png") || outFileFormat.toLowerCase().equals("gif")) { base = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } else if (outFileFormat.equals("jpg") || outFileFormat.toLowerCase().equals("bmp")) { base = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } // Create the base canvas that all other map elements will be draped on top of mapBaseGraphic = base.getGraphics(); mapBaseGraphic.setColor(Color.white); mapBaseGraphic.fillRect(0, 0, width, height); mapBaseGraphic.drawImage(base, 0, 0, null); // Ordering the layers from the default map DashboardLayer[] orderedLayers = this.getOrderedLayers(); // Add layers to the base canvas BufferedImage layerCanvas = getLayersExportCanvas(width, height, orderedLayers, mapBounds); // Get base map String baseType = null; try { JSONObject activeBaseObj = new JSONObject(activeBaseMap); baseType = activeBaseObj.getString("LAYER_SOURCE_TYPE"); } catch (JSONException e) { String error = "Could not active base map JSON."; throw new ProgrammingErrorException(error, e); } // Get bounds of the map if (baseType.length() > 0) { String bottom; String top; String right; String left; try { JSONObject mapBoundsObj = new JSONObject(mapBounds); bottom = mapBoundsObj.getString("bottom"); top = mapBoundsObj.getString("top"); right = mapBoundsObj.getString("right"); left = mapBoundsObj.getString("left"); } catch (JSONException e) { String error = "Could not parse map bounds."; throw new ProgrammingErrorException(error, e); } BufferedImage baseMapImage = this.getBaseMapCanvas(width, height, left, bottom, right, top, baseType); if (baseMapImage != null) { mapBaseGraphic.drawImage(baseMapImage, 0, 0, null); } } // Offset the layerCanvas so that it is center int widthOffset = (int) ((width - layerCanvas.getWidth()) / 2); int heightOffset = (int) ((height - layerCanvas.getHeight()) / 2); mapBaseGraphic.drawImage(layerCanvas, widthOffset, heightOffset, null); // Add legends to the base canvas BufferedImage legendCanvas = getLegendExportCanvas(width, height); mapBaseGraphic.drawImage(legendCanvas, 0, 0, null); } finally { ByteArrayOutputStream outStream = null; try { outStream = new ByteArrayOutputStream(); ImageIO.write(base, outFileFormat, outStream); inStream = new ByteArrayInputStream(outStream.toByteArray()); } catch (IOException e) { String error = "Could not write map image to the output stream."; throw new ProgrammingErrorException(error, e); } finally { if (outStream != null) { try { outStream.close(); } catch (IOException e) { String error = "Could not close stream."; throw new ProgrammingErrorException(error, e); } } } if (mapBaseGraphic != null) { mapBaseGraphic.dispose(); } } return inStream; }
From source file:distribuidos.MyThread.java
private void enviarImgRaiz() { String imagepath = Main.imagen; String newimagepath = Main.newimagen; BufferedImage original = null; try {// w ww. j av a 2 s . c o m original = ImageIO.read(new File(imagepath)); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } Graphics2D g2d = original.createGraphics(); g2d.setBackground(Color.WHITE); File f = new File(imagepath); try { ImageIO.write(original, "png", f); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } BufferedImage nueva = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB); File fn = new File(newimagepath); try { ImageIO.write(nueva, "png", fn); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } int filacero = 0; int partes = this.nodo.getNhijos(); int filasporparte = nueva.getHeight() / partes; int resto = nueva.getHeight() % partes; Mensaje tochild = new Mensaje(this.idnode); tochild.setCabecera("Imagen"); tochild.setContenido(""); tochild.setStr1(imagepath); tochild.setStr2(newimagepath); Iterator it = this.nodo.getHijos(); int y = filacero; while (it.hasNext()) { tochild.setReceptor((int) it.next()); tochild.setAux1(0); tochild.setAux2(y); tochild.setAux3(nueva.getWidth()); tochild.setAux4(filasporparte + resto); System.out.println("Envio a hijo"); this.enviarMensaje(tochild); try { EMDijkstra.acquire(); } catch (InterruptedException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } outDeficit++; //DIJKSTRA EMDijkstra.release(); y += filasporparte + resto; resto = 0; } }
From source file:com.zacwolf.commons.email.Email.java
public static BufferedImage makeRoundedFooter(int width, int cornerRadius, Color bgcolor, Color border) throws Exception { int height = (cornerRadius * 2) + 10; BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(bgcolor);// w w w. j av a 2s . c o m g2.fillRoundRect(0, 0, width, height - 1, cornerRadius, cornerRadius); g2.setComposite(AlphaComposite.SrcOver); if (border != null) { g2.setColor(border); g2.drawRoundRect(0, 0, width - 1, height - 2, cornerRadius, cornerRadius); } g2.dispose(); Rectangle clip = createClip(output, new Dimension(width, cornerRadius), 0, height - cornerRadius - 1); return output.getSubimage(clip.x, clip.y, clip.width, clip.height); }
From source file:org.jimcat.services.imagemanager.ImageUtil.java
/** * get a BufferedImageType of the given image used to replicate * // w w w . j a v a 2 s . c o m * @param img * @return the type of the buffered image */ private static int getImageType(BufferedImage img) { if (img.getTransparency() == Transparency.OPAQUE) { return BufferedImage.TYPE_INT_RGB; } return BufferedImage.TYPE_INT_ARGB; }
From source file:edu.ku.brc.specify.tools.FormDisplayer.java
/** * Generates an Image for the View.// ww w. j ava2s . c o m */ protected void generateViewImage(final ViewIFace view) { Rectangle rect = frame.getContentPane().getBounds(); if (rect.width == 0 || rect.height == 0) { return; } BufferedImage bufImage = new BufferedImage(rect.width, rect.height, (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB)); Graphics2D g2 = bufImage.createGraphics(); if (!doPNG) { g2.setColor(Color.WHITE); g2.fillRect(0, 0, rect.width, rect.height); } g2.setRenderingHints(ERDVisualizer.createTextRenderingHints()); frame.getContentPane().paint(g2); g2.dispose(); String baseFileName = outputDir.getAbsoluteFile() + "/" + view.getName() + "_" + viewInx; //$NON-NLS-1$ //$NON-NLS-2$ File imgFile = new File(baseFileName + (doPNG ? ".png" : ".jpg")); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(imgFile.getAbsolutePath()); try { ImageIO.write(bufImage, "PNG", imgFile); //$NON-NLS-1$ entries.add(new Pair<String, File>(view.getName(), imgFile)); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex); ex.printStackTrace(); } }
From source file:edu.umn.cs.spatialHadoop.operations.Plot.java
/** * Combines images of different datasets into one image that is displayed * to users.//from w w w. ja v a 2 s . c om * @param fs The file system that contains the datasets and images * @param files Paths to directories which contains the datasets * @param includeBoundaries Also plot the indexing boundaries of datasets * @return An image that is the combination of all datasets images * @throws IOException */ public static BufferedImage combineImages(Configuration conf, Path[] files, boolean includeBoundaries, int width, int height) throws IOException { BufferedImage result = null; // Retrieve the MBRs of all datasets Rectangle allMbr = new Rectangle(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); for (Path file : files) { FileSystem fs = file.getFileSystem(conf); Rectangle mbr = FileMBR.fileMBR(fs, file, null); allMbr.expand(mbr); } // Adjust width and height to maintain aspect ratio if ((allMbr.x2 - allMbr.x1) / (allMbr.y2 - allMbr.y1) > (double) width / height) { // Fix width and change height height = (int) ((allMbr.y2 - allMbr.y1) * width / (allMbr.x2 - allMbr.x1)); } else { width = (int) ((allMbr.x2 - allMbr.x1) * height / (allMbr.y2 - allMbr.y1)); } result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (Path file : files) { FileSystem fs = file.getFileSystem(conf); if (fs.getFileStatus(file).isDir()) { // Retrieve the MBR of this dataset Rectangle mbr = FileMBR.fileMBR(fs, file, null); // Compute the coordinates of this image in the whole picture mbr.x1 = (mbr.x1 - allMbr.x1) * width / allMbr.getWidth(); mbr.x2 = (mbr.x2 - allMbr.x1) * width / allMbr.getWidth(); mbr.y1 = (mbr.y1 - allMbr.y1) * height / allMbr.getHeight(); mbr.y2 = (mbr.y2 - allMbr.y1) * height / allMbr.getHeight(); // Retrieve the image of this dataset Path imagePath = new Path(file, "_data.png"); if (!fs.exists(imagePath)) throw new RuntimeException("Image " + imagePath + " not ready"); FSDataInputStream imageFile = fs.open(imagePath); BufferedImage image = ImageIO.read(imageFile); imageFile.close(); // Draw the image Graphics graphics = result.getGraphics(); graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(), (int) mbr.getHeight(), null); graphics.dispose(); if (includeBoundaries) { // Plot also the image of the boundaries // Retrieve the image of the dataset boundaries imagePath = new Path(file, "_partitions.png"); if (fs.exists(imagePath)) { imageFile = fs.open(imagePath); image = ImageIO.read(imageFile); imageFile.close(); // Draw the image graphics = result.getGraphics(); graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(), (int) mbr.getHeight(), null); graphics.dispose(); } } } } return result; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw a frame around the image; color depends on resolution if wanted * * @param movie//from w ww .j a v a 2s . c om * @param bi * @return */ private BufferedImage drawFrame(Movie movie, BufferedImage bi) { BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D newGraphics = newImg.createGraphics(); newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cornerRadius2 = 0; if (!movie.isHD()) { String[] colorSD = frameColorSD.split("/"); int[] lengthSD = new int[colorSD.length]; for (int i = 0; i < colorSD.length; i++) { lengthSD[i] = Integer.parseInt(colorSD[i]); } newGraphics.setPaint(new Color(lengthSD[0], lengthSD[1], lengthSD[2])); } else if (highdefDiff) { if (movie.isHD()) { // Otherwise use the 720p String[] color720 = frameColor720.split("/"); int[] length720 = new int[color720.length]; for (int i = 0; i < color720.length; i++) { length720[i] = Integer.parseInt(color720[i]); } newGraphics.setPaint(new Color(length720[0], length720[1], length720[2])); } if (movie.isHD1080()) { String[] color1080 = frameColor1080.split("/"); int[] length1080 = new int[color1080.length]; for (int i = 0; i < color1080.length; i++) { length1080[i] = Integer.parseInt(color1080[i]); } newGraphics.setPaint(new Color(length1080[0], length1080[1], length1080[2])); } } else { // We don't care, so use the default HD logo. String[] colorHD = frameColorHD.split("/"); int[] lengthHD = new int[colorHD.length]; for (int i = 0; i < colorHD.length; i++) { lengthHD[i] = Integer.parseInt(colorHD[i]); } newGraphics.setPaint(new Color(lengthHD[0], lengthHD[1], lengthHD[2])); } if (roundCorners) { cornerRadius2 = cornerRadius; } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(), rcqFactor * cornerRadius2, rcqFactor * cornerRadius2); newGraphics.setClip(rect); // image fitted into border newGraphics.drawImage(bi, (int) (rcqFactor * frameSize - 1), (int) (rcqFactor * frameSize - 1), (int) (bi.getWidth() - (rcqFactor * frameSize * 2) + 2), (int) (bi.getHeight() - (rcqFactor * frameSize * 2) + 2), null); BasicStroke s4 = new BasicStroke(rcqFactor * frameSize * 2); newGraphics.setStroke(s4); newGraphics.draw(rect); newGraphics.dispose(); return newImg; }
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
private Queue<BufferedImage> createFooter() { // creating a backbuffer image on which we should draw the bkgColor for this colormap element final BufferedImage image = ImageUtils.createImage(1, 1, (IndexColorModel) null, transparent); final Map<Key, Object> hintsMap = new HashMap<Key, Object>(); final Graphics2D graphics = ImageUtils.prepareTransparency(transparent, backgroundColor, image, hintsMap); // list where we store the rows for the footer final Queue<BufferedImage> queue = new LinkedList<BufferedImage>(); // //the height is already fixed // final int rowHeight=(int)Math.round(rowH); final int rowWidth = (int) Math.round(footerW); // final Rectangle clipboxA=new Rectangle(0,0,rowWidth,rowHeight); ////from w ww .j av a2s . c o m // footer // // // draw the various bodyCells for (Cell cell : footerRows) { // get dim final Dimension dim = cell.getPreferredDimension(graphics); // final int rowWidth=(int)Math.round(dim.getWidth()); final int rowHeight = (int) Math.round(dim.getHeight()); final Rectangle clipboxA = new Rectangle(0, 0, rowWidth, rowHeight); // draw it final BufferedImage colorCellLegend = new BufferedImage(rowWidth, rowHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D rlg = colorCellLegend.createGraphics(); rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); cell.draw(rlg, clipboxA, border); rlg.dispose(); queue.add(colorCellLegend); } graphics.dispose(); return queue;// mergeRows(queue); }
From source file:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java
private Object prepareLegend(String legendKey, XMLAdapter jrxmlAdapter, List<OrderedDatasource<?>> datasources, String type, int resolution) throws ProcessletException { if ("net.sf.jasperreports.engine.JRRenderable".equals(type)) { return new LegendRenderable(datasources, resolution); } else {/*from w ww .j a v a 2 s . c o m*/ OMElement legendRE = jrxmlAdapter.getElement(jrxmlAdapter.getRootElement(), new XPath( ".//jasper:image[jasper:imageExpression/text()='$P{" + legendKey + "}']/jasper:reportElement", nsContext)); if (legendRE != null) { LOG.debug("Found legend with key '" + legendKey + "'."); int width = jrxmlAdapter.getRequiredNodeAsInteger(legendRE, new XPath("@width", nsContext)); int height = jrxmlAdapter.getRequiredNodeAsInteger(legendRE, new XPath("@height", nsContext)); width = adjustSpan(width, resolution); height = adjustSpan(height, resolution); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); // TODO: bgcolor? Color bg = Color.decode("0xFFFFFF"); g.setColor(bg); g.fillRect(0, 0, width, height); g.setColor(Color.BLACK); int k = 0; for (int i = 0; i < datasources.size(); i++) { if (k > height) { LOG.warn("The necessary legend size is larger than the available legend space."); } List<Pair<String, BufferedImage>> legends = datasources.get(i).getLegends(width); for (Pair<String, BufferedImage> legend : legends) { BufferedImage img = legend.second; if (img != null) { if (img.getWidth(null) < 50) { // it is assumed that no label is assigned g.drawImage(img, 0, k, null); g.drawString(legend.first, img.getWidth(null) + 10, k + img.getHeight(null) / 2); } else { g.drawImage(img, 0, k, null); } k = k + img.getHeight(null) + 10; } else { g.drawString("- " + legend.first, 0, k + 10); k = k + 20; } } } g.dispose(); return convertImageToReportFormat(type, bi); } } return null; }
From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java
/** * /* w w w .j a v a 2 s . co m*/ */ public void generate() { Rectangle rect = getPanel().getParent().getBounds(); System.out.println("MAIN[" + rect + "]"); if (rect.width == 0 || rect.height == 0) { return; } BufferedImage bufImage = new BufferedImage(rect.width, rect.height, (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB)); Graphics2D g2 = bufImage.createGraphics(); if (!doPNG) { g2.setColor(Color.WHITE); g2.fillRect(0, 0, rect.width, rect.height); } g2.setRenderingHints(createTextRenderingHints()); g2.setFont(tblTracker.getFont()); getPanel().getParent().paint(g2); g2.dispose(); Component stop = getPanel().getParent(); Point p = new Point(0, 0); calcLoc(p, getPanel().getMainTable(), stop); String name = StringUtils.substringAfterLast(getPanel().getMainTable().getClassName(), "."); DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(name); String fName = schemaDir.getAbsolutePath() + File.separator + name; try { String origName = fName; int i = 1; while (pngNameHash.contains(fName)) { fName = origName + i; } pngNameHash.add(fName); File html = new File(fName + ".html"); BufferedWriter output = new BufferedWriter(new FileWriter(html)); int index = mapTemplate.indexOf(contentTag); String subContent = mapTemplate.substring(0, index); output.write(StringUtils.replace(subContent, "<!-- Title -->", tblInfo.getTitle())); File imgFile = new File(fName + (doPNG ? ".png" : ".jpg")); output.write("<map name=\"schema\" id=\"schema\">\n"); Vector<ERDTable> nList = mainPanel.isRoot() ? tblTracker.getTreeAsList(mainPanel.getMainTable()) : getPanel().getRelTables(); for (ERDTable erdt : nList) { p = new Point(0, 0); calcLoc(p, erdt, stop); Dimension s = erdt.getSize(); String linkname = StringUtils.substringAfterLast(erdt.getClassName(), "."); output.write("<area shape=\"rect\" coords=\"" + p.x + "," + p.y + "," + (p.x + s.width) + "," + (p.y + s.height) + "\" href=\"" + linkname + ".html\"/>\n"); } output.write("</map>\n"); output.write("<img border=\"0\" usemap=\"#schema\" src=\"" + imgFile.getName() + "\"/>\n"); output.write(mapTemplate.substring(index + contentTag.length() + 1, mapTemplate.length())); output.close(); File oFile = new File(schemaDir + File.separator + imgFile.getName()); System.out.println(oFile.getAbsolutePath()); if (doPNG) { ImageIO.write(bufImage, "PNG", oFile); } else { writeJPEG(oFile, bufImage, 0.75f); } //ImageIO.write(bufImage, "JPG", new File(schemaDir + File.separator + imgFile.getName()+".jpg")); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e); e.printStackTrace(); } }