List of usage examples for java.awt Graphics2D dispose
public abstract void dispose();
From source file:Main.java
public static void main(String[] argv) throws Exception { Image image = new ImageIcon("image.gif").getImage(); BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g = bimage.createGraphics(); g.drawImage(image, 0, 0, null);//from ww w . j a v a2s . c om g.dispose(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_PRINTSCREEN); robot.delay(40);//w w w. ja v a 2 s .com robot.keyRelease(KeyEvent.VK_PRINTSCREEN); robot.delay(404); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); DataFlavor[] flavors = cb.getAvailableDataFlavors(); for (DataFlavor flavor : flavors) { if (flavor.toString().indexOf("java.awt.Image") <= 0) { continue; } Image i = (Image) cb.getData(flavor); BufferedImage bi = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.drawImage(i, 0, 0, null); g.dispose(); ImageIO.write(bi, "png", new File("c:/Java_Dev/test.png")); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int w, h;//from w w w .j a v a2 s .c o m w = 150; h = 150; Ellipse2D.Double circle = new Ellipse2D.Double(12, 12, 12, 12); Document document = new Document(new Rectangle(w, h)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sun_tutorial.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); Graphics2D g2 = cb.createGraphics(w, h); g2.setColor(Color.green); g2.fill(circle); g2.dispose(); document.close(); }
From source file:G2DDrawStringPDF.java
public static void main(String[] args) { Document document = new Document(); try {//from w w w. j a v a 2 s . c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("G2DDrawStringPDF.pdf")); document.open(); DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); mapper.insertDirectory("c:\\windows\\fonts"); int w = 150; int h = 150; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h, mapper); g2.drawString("text", 20, 20); g2.dispose(); cb.addTemplate(tp, 50, 400); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage large = ImageIO.read(new File("images/a.jpg")); BufferedImage small = ImageIO.read(new File("images/b.jpg")); int w = large.getWidth(); int h = large.getHeight(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(w, h, type); Graphics2D g2 = image.createGraphics(); g2.drawImage(large, 0, 0, null);/*from w w w.j ava2s. c o m*/ g2.drawImage(small, 10, 10, null); g2.dispose(); ImageIO.write(image, "jpg", new File("new.jpg")); JOptionPane.showMessageDialog(null, new ImageIcon(image), "", JOptionPane.PLAIN_MESSAGE); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("h.pdf")); document.open();/* www. j a v a 2s . c om*/ PdfContentByte cb = writer.getDirectContent(); Graphics2D graphics2D = cb.createGraphics(PageSize.A4.width(), PageSize.A4.height()); graphics2D.drawString("Hello World", 36, 54); graphics2D.dispose(); document.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { final int SCALE = 2; Image img = new ImageIcon(new URL("http://www.java2s.com/style/download.png")).getImage(); BufferedImage bi = new BufferedImage(SCALE * img.getWidth(null), SCALE * img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D grph = (Graphics2D) bi.getGraphics(); grph.scale(SCALE, SCALE);/*from ww w. j a va 2 s . c o m*/ grph.drawImage(img, 0, 0, null); grph.dispose(); ImageIO.write(bi, "png", new File("double_size.png")); }
From source file:org.jfree.chart.demo.LegendTitleToImageDemo1.java
public static void main(String args[]) throws IOException { DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("A", 1.0D); defaultpiedataset.setValue("B", 2D); defaultpiedataset.setValue("C", 3D); JFreeChart jfreechart = ChartFactory.createPieChart("Test", defaultpiedataset, true, false, false); LegendTitle legendtitle = jfreechart.getLegend(); legendtitle.setMargin(0.0D, 0.0D, 1.0D, 1.0D); BufferedImage bufferedimage = new BufferedImage(1, 1, 2); Graphics2D graphics2d = bufferedimage.createGraphics(); Size2D size2d = legendtitle.arrange(graphics2d); graphics2d.dispose(); int i = (int) Math.rint(size2d.width); int j = (int) Math.rint(size2d.height); BufferedImage bufferedimage1 = new BufferedImage(i, j, 2); Graphics2D graphics2d1 = bufferedimage1.createGraphics(); legendtitle.draw(graphics2d1, new java.awt.geom.Rectangle2D.Double(0.0D, 0.0D, i, j)); graphics2d1.dispose();/* w ww.j a va 2 s. c o m*/ BufferedOutputStream bufferedoutputstream = new BufferedOutputStream( new FileOutputStream(new File("LegendTitleToImageDemo1.png"))); ChartUtilities.writeBufferedImageAsPNG(bufferedoutputstream, bufferedimage1); bufferedoutputstream.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL urlImage1 = new URL("http://www.java2s.com/style/download.png"); final Image fgImage = ImageIO.read(urlImage1); int w = fgImage.getWidth(null); int h = fgImage.getHeight(null); final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = finalImage.createGraphics(); g.drawImage(bgImage, 0, 0, null);// ww w . j av a2 s . c om g.drawImage(fgImage, 0, 0, null); g.dispose(); Runnable r = new Runnable() { @Override public void run() { JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5)); gui.add(new JLabel(new ImageIcon(bgImage))); gui.add(new JLabel(new ImageIcon(fgImage))); gui.add(new JLabel(new ImageIcon(finalImage))); JOptionPane.showMessageDialog(null, gui); } }; SwingUtilities.invokeLater(r); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); document.open();/*from w w w. j a v a2s .c o m*/ String text = "\u5e73\u548C"; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(100, 50); Graphics2D g2 = tp.createGraphicsShapes(100, 50); java.awt.Font font = new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 12); g2.setFont(font); g2.drawString(text, 0, 40); g2.dispose(); cb.addTemplate(tp, 36, 780); document.close(); }