1 18 package org.apache.batik.svggen; 19 20 import java.awt.*; 21 import java.awt.geom.*; 22 import java.awt.image.*; 23 24 30 public class DrawImage implements Painter { 31 public void paint(Graphics2D g) { 32 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 33 RenderingHints.VALUE_ANTIALIAS_ON); 34 35 BufferedImage image = new BufferedImage(100, 75, BufferedImage.TYPE_INT_ARGB); 37 Graphics2D ig = image.createGraphics(); 38 ig.scale(.5, .5); 39 ig.setPaint(new Color(128,0,0)); 40 ig.fillRect(0, 0, 100, 50); 41 ig.setPaint(Color.orange); 42 ig.fillRect(100, 0, 100, 50); 43 ig.setPaint(Color.yellow); 44 ig.fillRect(0, 50, 100, 50); 45 ig.setPaint(Color.red); 46 ig.fillRect(100, 50, 100, 50); 47 ig.setPaint(new Color(255, 127, 127)); 48 ig.fillRect(0, 100, 100, 50); 49 ig.setPaint(Color.black); 50 ig.draw(new Rectangle2D.Double(0.5, 0.5, 199, 149)); 51 ig.dispose(); 52 53 g.drawImage(image, 5, 10, Color.gray, null); 55 g.translate(150, 0); 56 57 g.drawImage(image, 5, 10, 50, 40, null); 59 g.translate(-150, 80); 60 61 g.drawImage(image, 5, 10, 45, 40, 50, 0, 100, 25, null); 63 g.translate(150, 0); 64 65 g.drawImage(image, 5, 10, 45, 40, 50, 50, 100, 75, Color.gray, null); 67 g.translate(-150, 80); 68 69 AffineTransform at = new AffineTransform(); 71 at.scale(.5, .3); 72 at.translate(5, 10); 73 g.drawImage(image, at, null); 74 75 g.translate(150, 0); 76 77 RescaleOp op = new RescaleOp(.5f, 0f, null); 79 g.drawImage(image,op,5,10); 80 81 g.translate(-150, 0); 82 83 g.translate(0, 80); 84 85 g.drawImage(image, 5, 10, 50, 40, Color.gray, null); 87 88 } 89 } 90 | Popular Tags |