List of usage examples for java.awt Image getHeight
public abstract int getHeight(ImageObserver observer);
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberComposite.java
private void updateLegend() { try {// w w w . jav a 2 s . com ArrayList<Image> legends = new ArrayList<Image>(4); if (singleRenderer != null && singleRenderer.getLegend() != null) { legends.add(singleRenderer.getLegend()); } if (rowGroupRenderer != null && rowGroupRenderer.getLegend() != null) { legends.add(rowGroupRenderer.getLegend()); } if (columnGroupRenderer != null && columnGroupRenderer.getLegend() != null) { legends.add(columnGroupRenderer.getLegend()); } if (rowColumnGroupRenderer != null && rowColumnGroupRenderer.getLegend() != null) { legends.add(rowColumnGroupRenderer.getLegend()); } if (!legends.isEmpty()) { int margin = 5; int imageWidth = 0; int imageHeight = 0; for (Image l : legends) { imageHeight += margin * 2 + l.getHeight(null); if (imageWidth < l.getWidth(null)) { imageWidth = l.getWidth(null); } } imageWidth += margin * 2; if (imageWidth > 0 && imageHeight > 0) { legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT); Graphics2D g2D = legend.createGraphics(); g2D.translate(margin, 0); for (Image l : legends) { g2D.translate(0, margin); g2D.drawImage(l, 0, 0, null); g2D.translate(0, margin + l.getHeight(null)); } g2D.dispose(); } } } catch (Exception e) { } }
From source file:com.wet.wired.jsr.player.JPlayer.java
public void showNewImage(final Image image) { if (icon == null) { icon = new ImageIcon(image); JLabel label = new JLabel(icon); scrollPane = new JScrollPane(label); scrollPane.setSize(image.getWidth(this), image.getHeight(this)); SwingUtilities.invokeLater(new Runnable() { public void run() { getContentPane().add(scrollPane, BorderLayout.CENTER); pack();//from ww w. j av a 2 s.c o m setSize(getWidth() - 100, 400); setVisible(true); repaint(0); } }); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { icon.setImage(image); repaint(0); } }); } }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java
private BufferedImage convertImgToBufferedImg(Image limage, String l) { if (limage instanceof BufferedImage) { return ((BufferedImage) limage); } else {// w w w. java 2 s. com Image lImage = new ImageIcon(limage).getImage(); BufferedImage bufferedimage = new BufferedImage(lImage.getWidth(null), lImage.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics gr = bufferedimage.createGraphics(); gr.drawImage(lImage, 0, 0, null); gr.dispose(); return (bufferedimage); } }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
public void paintIcons(Graphics2D g, StateRenderer2D renderer) { for (AssetTrack track : assets.values()) { AssetPosition p = track.getLatest(newestTimestampSelection); if (p == null || hiddenPosTypes.contains(p.getType())) continue; if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Point2D pt = renderer.getScreenPosition(p.getLoc()); //TODO paint icon here Image img = getIcon(p); if (img != null) { g.drawImage(img, (int) (pt.getX() - 8), (int) (pt.getY() - 8), (int) (pt.getX() + 8), (int) (pt.getY() + 8), 0, 0, img.getWidth(null), img.getHeight(null), null); }//from w ww . ja va 2 s . c om } }
From source file:org.apache.tika.parser.ocr.TesseractOCRParser.java
public void parse(Image image, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { TemporaryResources tmp = new TemporaryResources(); FileOutputStream fos = null;//from www.ja va2 s. co m TikaInputStream tis = null; try { int w = image.getWidth(null); int h = image.getHeight(null); BufferedImage bImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); File file = tmp.createTemporaryFile(); fos = new FileOutputStream(file); ImageIO.write(bImage, "png", fos); tis = TikaInputStream.get(file); parse(tis, handler, metadata, context); } finally { tmp.dispose(); if (tis != null) tis.close(); if (fos != null) fos.close(); } }
From source file:J3dSwingFrame.java
/** * Set the texture on our goemetry//w ww . java 2s . c o m * <P> * Always specified as a URL so that we may fetch it from anywhere. * * @param url * The url to the image. */ public void setTexture(URL url) { Toolkit tk = Toolkit.getDefaultToolkit(); Image src_img = tk.createImage(url); BufferedImage buf_img = null; if (!(src_img instanceof BufferedImage)) { // create a component anonymous inner class to give us the image // observer we need to get the width and height of the source image. Component obs = new Component() { }; int width = src_img.getWidth(obs); int height = src_img.getHeight(obs); // construct the buffered image from the source data. buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = buf_img.getGraphics(); g.drawImage(src_img, 0, 0, null); g.dispose(); } else buf_img = (BufferedImage) src_img; src_img.flush(); ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img); texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight()); appearance.setTexture(texture); buf_img.flush(); }
From source file:org.getobjects.appserver.publisher.GoDefaultRenderer.java
/** * Renders an arbitary java.awt.Image object by converting it to a * BufferedImage and then calling renderBufferedImage. * /*www . jav a 2s . co m*/ * @param _img - the java.awt.Image to be rendered * @param _ctx - the context to render the Image in * @return null if everything went fine, an exception otherwise */ public Exception renderImage(Image _img, WOContext _ctx) { /* Not sure whether thats the best way to accomplish this :-) */ if (_img == null) return new GoInternalErrorException("got no image to render"); if (_img instanceof BufferedImage) return this.renderBufferedImage((BufferedImage) _img, _ctx); int width = _img.getWidth(null); int height = _img.getHeight(null); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi.createGraphics(); g2d.drawImage(_img, 0, 0, width, height, null); return this.renderBufferedImage(bi, _ctx); }
From source file:org.getobjects.appserver.publisher.JoDefaultRenderer.java
/** * Renders an arbitary java.awt.Image object by converting it to a * BufferedImage and then calling renderBufferedImage. * //from w w w . j a v a2 s .com * @param _img - the java.awt.Image to be rendered * @param _ctx - the context to render the Image in * @return null if everything went fine, an exception otherwise */ public Exception renderImage(Image _img, WOContext _ctx) { /* Not sure whether thats the best way to accomplish this :-) */ if (_img == null) return new JoInternalErrorException("got no image to render"); if (_img instanceof BufferedImage) return this.renderBufferedImage((BufferedImage) _img, _ctx); int width = _img.getWidth(null); int height = _img.getHeight(null); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi.createGraphics(); g2d.drawImage(_img, 0, 0, width, height, null); return this.renderBufferedImage(bi, _ctx); }
From source file:org.rdv.viz.chart.FastXYItemRenderer.java
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { boolean itemVisible = getItemVisible(series, item); // setup for collecting optional entity info... Shape entityArea = null;/*from w w w .ja va 2 s .co m*/ EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(seriesStroke); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(x1) || Double.isNaN(y1)) { itemVisible = false; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getPlotLines()) { if (item == 0) { previousDrawnItem = 1; } if (getDrawSeriesLineAsPath()) { State s = (State) state; if (s.getSeriesIndex() != series) { // we are starting a new series path s.seriesPath.reset(); s.setLastPointGood(false); s.setSeriesIndex(series); } // update path to reflect latest point if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.isLastPointGood()) { // TODO: check threshold s.seriesPath.lineTo(x, y); } else { s.seriesPath.moveTo(x, y); } s.setLastPointGood(true); } else { s.setLastPointGood(false); } if (item == dataset.getItemCount(series) - 1) { if (s.getSeriesIndex() == series) { // draw path g2.setStroke(lookupSeriesStroke(series)); g2.setPaint(lookupSeriesPaint(series)); g2.draw(s.seriesPath); } } } else if (item != 0 && itemVisible) { // get the previous data point... double x0 = dataset.getXValue(series, item - previousDrawnItem); double y0 = dataset.getYValue(series, item - previousDrawnItem); if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data point is within the threshold int numX = dataset.getItemCount(series); double minX = dataset.getXValue(series, 0); double maxX = dataset.getXValue(series, numX - 1); if (getGapThresholdType() == UnitType.ABSOLUTE) { drawLine = Math.abs(x1 - x0) <= getGapThreshold(); } else { drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } // Only draw line if it is more than a pixel away from the // previous one if ((transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2 || transY1 - transY0 < -2)) { previousDrawnItem = 1; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.draw(state.workingLine); } } else { // Increase counter for the previous drawn item. previousDrawnItem++; } } } } } // we needed to get this far even for invisible items, to ensure that // seriesPath updates happened, but now there is nothing more we need // to do for non-visible items... if (!itemVisible) { return; } // add a cursor to indicate the position of the last data item if (getCursorVisible() && item == dataset.getItemCount(series) - 1) { Line2D cursorX = new Line2D.Double(transX1 - DEFAULT_CURSOR_SIZE, transY1, transX1 + DEFAULT_CURSOR_SIZE, transY1); g2.draw(cursorX); Line2D cursorY = new Line2D.Double(transX1, transY1 - DEFAULT_CURSOR_SIZE, transX1, transY1 + DEFAULT_CURSOR_SIZE); g2.draw(cursorY); } if (getBaseShapesVisible()) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { g2.fill(shape); } else { g2.draw(shape); } } entityArea = shape; } if (getPlotImages()) { Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item... if (entities != null && dataArea.contains(xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
From source file:Animator.java
/** * Get the dimensions of an image./*from w w w . j a va2s .c om*/ * * @return the image's dimensions. */ Dimension getImageDimensions(Image im) { return new Dimension(im.getWidth(null), im.getHeight(null)); }