List of usage examples for java.awt Graphics2D drawImage
public abstract boolean drawImage(Image img, AffineTransform xform, ImageObserver obs);
From source file:Java2DExample.java
public ImagePanel(URL imageURL) { image = Toolkit.getDefaultToolkit().createImage(imageURL); MediaTracker mediaTracker = new MediaTracker(this); mediaTracker.addImage(image, 0);//from w w w . j a v a2s .c o m try { mediaTracker.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } originalImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); displayImage = originalImage; Graphics2D graphics = displayImage.createGraphics(); graphics.drawImage(image, null, null); }
From source file:ImagePanel.java
public void paintComponent(Graphics grp) { Rectangle rect = this.getBounds(); Graphics2D g2d = (Graphics2D) grp; transform.setToTranslation((rect.width - w) / 2, (rect.height - h) / 2); transform.rotate(Math.toRadians(angle), w / 2, h / 2); g2d.drawImage(image, transform, this); }
From source file:IDlook.java
private void createThumbnail() { int maxDim = 350; try {/* w w w .j a v a 2s. c o m*/ Image inImage = icon.getImage(); double scale = (double) maxDim / (double) inImage.getHeight(null); if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) maxDim / (double) inImage.getWidth(null); } int scaledW = (int) (scale * inImage.getWidth(null)); int scaledH = (int) (scale * inImage.getHeight(null)); BufferedImage outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB); AffineTransform tx = new AffineTransform(); if (scale < 1.0d) { tx.scale(scale, scale); } Graphics2D g2d = outImage.createGraphics(); g2d.drawImage(inImage, tx, null); g2d.dispose(); iconThumbnail = new ImageIcon(outImage); } catch (Exception e) { e.printStackTrace(); } }
From source file:ddf.catalog.transformer.input.tika.TikaInputTransformer.java
private void createThumbnail(InputStream input, Metacard metacard) { try {/*from w ww . j av a 2s.co m*/ Image image = ImageIO.read(new CloseShieldInputStream(input)); if (null != image) { BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = bufferedImage.createGraphics(); graphics.drawImage(image, null, null); graphics.dispose(); BufferedImage thumb = Scalr.resize(bufferedImage, 200); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { ImageIO.write(thumb, "jpeg", out); byte[] thumbBytes = out.toByteArray(); metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, thumbBytes)); } } else { LOGGER.warn("Unable to read image from input stream to create thumbnail."); } } catch (Exception e) { LOGGER.warn("Unable to read image from input stream to create thumbnail.", e); } }
From source file:bachelorthesis.captchabuilder.builder.CaptchaBuilder.java
private BufferedImage flattenImage() { BufferedImage rImage;/* w w w . ja v a2 s .com*/ if (bg == null) { rImage = new BackgroundProducerBuilder(BackgroundProducerType.TRANSPARENT).create() .getBackground(img.getWidth(), img.getHeight()); } else { rImage = bg; } // Paint the main image over the background Graphics2D g = rImage.createGraphics(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g.drawImage(img, null, null); return rImage; }
From source file:Main.java
public void paint(Graphics g) { try {/*w w w . j a v a 2 s . com*/ Graphics2D g2D; g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String fileName = "a.jpg"; Image img = getToolkit().getImage(fileName); AffineTransform aTran = new AffineTransform(); aTran.translate(50.0f, 20.0f); g2D.transform(aTran); g2D.drawImage(img, new AffineTransform(), this); } catch (Exception e) { } }
From source file:BufferedImageThread.java
public void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize();//from w w w .j ava 2 s . c o m bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); step(d.width, d.height); AffineTransform at = new AffineTransform(); at.setToIdentity(); at.translate(x, y); at.rotate(Math.toRadians(rotate)); at.scale(scale, scale); big.drawImage(image, at, this); Graphics2D g2D = (Graphics2D) g; g2D.drawImage(bi, 0, 0, null); big.dispose(); }
From source file:TextBouncer.java
public BufferedImage makeBufferedImage(Image image, int imageType) { if (waitForImage(image) == false) return null; BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), imageType); Graphics2D g2 = bufferedImage.createGraphics(); g2.drawImage(image, null, null); return bufferedImage; }
From source file:ImageBouncer.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; setTransform(g2);/*w w w . ja v a2s . co m*/ setBilinear(g2); // Draw the image. g2.drawImage(image, AffineTransform.getTranslateInstance(mX, mY), null); }
From source file:ImageDrawingComponent.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; switch (opIndex) { case 0: /* copy */ g.drawImage(bi, 0, 0, null);/* ww w.ja v a 2 s . c o m*/ break; case 1: /* scale up using coordinates */ g.drawImage(bi, 0, 0, w, h, /* dst rectangle */ 0, 0, w / 2, h / 2, /* src area of image */ null); break; case 2: /* scale down using transform */ g2.drawImage(bi, AffineTransform.getScaleInstance(0.7, 0.7), null); break; case 3: /* scale up using transform Op and BICUBIC interpolation */ AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5); AffineTransformOp aop = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC); g2.drawImage(bi, aop, 0, 0); break; case 4: /* low pass filter */ case 5: /* sharpen */ float[] data = (opIndex == 4) ? BLUR3x3 : SHARPEN3x3; ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null); g2.drawImage(bi, cop, 0, 0); break; case 6: /* rescale */ RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); g2.drawImage(bi, rop, 0, 0); break; case 7: /* lookup */ byte lut[] = new byte[256]; for (int j = 0; j < 256; j++) { lut[j] = (byte) (256 - j); } ByteLookupTable blut = new ByteLookupTable(0, lut); LookupOp lop = new LookupOp(blut, null); g2.drawImage(bi, lop, 0, 0); break; default: } }