List of usage examples for java.awt Graphics2D drawImage
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y);
From source file:GeneralPathDemo.java
public void paintComponent(Graphics g) { // super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (firstTime) { Dimension dim = getSize(); int w = dim.width; int h = dim.height; oddShape = createPath();//from ww w . j a va 2s . c o m area = new Rectangle(w, h); bi = (BufferedImage) createImage(w, h); big = bi.createGraphics(); big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); firstTime = false; } // Clears the shape that was previously drawn. big.setColor(Color.white); big.fillRect(0, 0, area.width, area.height); big.setColor(Color.magenta); big.setStroke(new BasicStroke(3.0f)); big.draw(oddShape); // Draws the buffered image to the screen. g2.drawImage(bi, 0, 0, this); }
From source file:biz.ixnay.pivot.charts.skin.jfree.JFreeChartViewSkin.java
@Override public void paint(Graphics2D graphics) { int width = getWidth(); int height = getHeight(); if (bufferedImage == null || bufferedImage.getWidth() != width || bufferedImage.getHeight() != height) { chart = createChart();// w ww .j av a2 s . c o m bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D bufferedImageGraphics = (Graphics2D) bufferedImage.getGraphics(); java.awt.Rectangle area = new java.awt.Rectangle(0, 0, width, height); chart.setBackgroundPaint(null); chart.getPlot().setBackgroundPaint(getBackgroundColor()); chart.draw(bufferedImageGraphics, area, chartRenderingInfo); bufferedImageGraphics.dispose(); } graphics.drawImage(bufferedImage, 0, 0, null); }
From source file:de._13ducks.cor.graphics.GraphicsComponent.java
private void paint_debug(Graphics2D g2) { System.out.println("Printing Debug-Tree to 0,0"); g2.drawImage(imgMap.get("img/fix/testtree1.png").getImage(), 0, 0, null); }
From source file:com.alkacon.opencms.v8.weboptimization.CmsOptimizationSprite.java
/** * Add a new image to the given sprite.<p> * // w ww .j av a 2 s. c o m * @param sprite the sprite to modify * @param image the image to add * @param options the sprite options * * @return the modified sprite */ public BufferedImage addImage(BufferedImage sprite, BufferedImage image, CmsOptimizationSpriteOptions options) { // check the sprite size int newWidth = -1; if (sprite.getWidth() < options.getX() + image.getWidth()) { newWidth = options.getX() + image.getWidth(); } int newHeight = -1; if (sprite.getHeight() < options.getY() + image.getHeight()) { newHeight = options.getY() + image.getHeight(); } Graphics2D g2d = sprite.createGraphics(); if ((newHeight > 0) || (newWidth > 0)) { // adjust sprite size if needed if (newHeight < 0) { newHeight = sprite.getHeight(); } if (newWidth < 0) { newWidth = sprite.getWidth(); } // clone the sprite BufferedImage s2 = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_4BYTE_ABGR); g2d = s2.createGraphics(); g2d.drawImage(sprite, 0, 0, null); sprite = s2; } // put the image into the sprite g2d.drawImage(image, options.getX(), options.getY(), null); return sprite; }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize();//from ww w .j av a 2 s .c o m //System.out.println("d: "+d+" "+g.getClipBounds()); Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHints(renderingHints); FontMetrics fm = g2d.getFontMetrics(); int imgY = img1 != null ? (d.height - 24) / 2 : 0; int imgY2 = img1 != null ? (d.height - 16) / 2 : 0; int txtY = ((d.height - fm.getHeight()) / 2) + fm.getAscent(); int x = 0; Color color = g2d.getColor(); if (img1 != null) { g2d.drawImage(img1.getImage(), x, imgY, null); x += img1.getIconWidth(); } int iconInx = 0; if (txt1 != null) { x += getIconTextGap(); g2d.setColor(getForeground()); g.drawString(txt1, x, txtY); x += fm.stringWidth(txt1); g2d.setColor(color); } if (isContainer) { //if (isSelected && isEditable) //{ // x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete the container //} if (hasColObj) { if (img2 != null) { x += 1; x += iconSep; g2d.drawImage(img2.getImage(), x, imgY2, null); x += img2.getIconWidth(); } if (txt2 != null) { x += getIconTextGap(); g2d.setColor(getForeground()); g.drawString(txt2, x, txtY); x += fm.stringWidth(txt2); g2d.setColor(color); } if (isSelected) { x += iconSep; x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++); if (isEditable) { x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); } } } else if (isSelected) // No Col Obj { x += iconSep; x += drawIcon(g2d, x, imgY2, schImgIcon, iconInx++); x += drawIcon(g2d, x, imgY2, addImgIcon, iconInx++); } } else if (isSelected) { x += iconSep; x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++); // View for Collection Object //if (!isViewMode) //{ // x += iconSep; // x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete for Collection Object //} } g2d.dispose(); }
From source file:de.fhg.igd.mapviewer.AbstractTileOverlayPainter.java
/** * Draws the overlay image on a tile.//w ww . j a v a 2 s.c om * * @param gfx the graphics to draw the overlay on (with the origin being the * at the upper left corner of the tile) * @param img the overlay image * @param zoom the current zoom level * @param tilePosX the tile x position in world pixel coordinates * @param tilePosY the tile y position in world pixel coordinates * @param tileWidth the tile width * @param tileHeight the tile height * @param viewportBounds the view-port bounds * @param converter the pixel converter */ protected void drawOverlay(Graphics2D gfx, BufferedImage img, int zoom, int tilePosX, int tilePosY, int tileWidth, int tileHeight, Rectangle viewportBounds, PixelConverter converter) { gfx.drawImage(img, 0, 0, null); }
From source file:com.alvermont.terraj.util.io.ImagePrinter.java
/** * Render an image for printing.// ww w .ja v a 2s . c o m * * @param graphics The graphics context to print on * @param pageFormat The page format being used * @param pageIndex The page being printed * @throws java.awt.print.PrinterException If there is an error in printing * @return An indication of the result of page rendering for this page */ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { final Graphics2D g2 = (Graphics2D) graphics; // we only expect to be printing 1 page as the image is scaled if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; } // translate the coordinate system to match up the image with // the printable area g2.translate(getFormat().getImageableX(), pageFormat.getImageableY()); final Rectangle componentBounds = new Rectangle(getImage().getWidth(), getImage().getHeight()); g2.translate(-componentBounds.x, -componentBounds.y); // scale the image to fit scaleToFit(true); g2.scale(getScaleX(), getScaleY()); // render the image g2.drawImage(getImage(), null, 0, 0); // done return Printable.PAGE_EXISTS; }
From source file:com.frochr123.fabqr.gui.FabQRUploadDialog.java
private void btnPhotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPhotoActionPerformed // Get latest full camera image (without resize) latestFullCameraImage = null;/*from ww w. j a v a 2 s. c o m*/ if (cameraThread != null) { Image image = cameraThread.getLatestRawImage(); // Convert image to bufferedimage if (image != null) { BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bufferedImage.createGraphics(); graphics.drawImage(image, 0, 0, null); graphics.dispose(); latestFullCameraImage = bufferedImage; } } // Stop camera, freeze image closeCamera(); // Set correct UI button states btnPhoto.setEnabled(false); btnPhotoRedo.setEnabled(true); btnPublish.setEnabled(true); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberComposite.java
private void updateLegend() { try {/*www. j a va 2s . c o m*/ 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:Composite.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();//from w w w . j ava 2 s. com int w = d.width; int h = d.height; // Creates the buffered image. BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); // Clears the previously drawn image. g2.setColor(Color.white); g2.fillRect(0, 0, d.width, d.height); int rectx = w / 4; int recty = h / 4; // Draws the rectangle and ellipse into the buffered image. gbi.setColor(new Color(0.0f, 0.0f, 1.0f, 1.0f)); gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100)); gbi.setColor(new Color(1.0f, 0.0f, 0.0f, 1.0f)); gbi.setComposite(ac); gbi.fill(new Ellipse2D.Double(rectx + rectx / 2, recty + recty / 2, 150, 100)); // Draws the buffered image. g2.drawImage(buffImg, null, 0, 0); }