1 18 package org.apache.batik.svggen; 19 20 import java.awt.*; 21 import java.awt.geom.*; 22 import java.awt.image.*; 23 24 33 public class GraphicObjects implements Painter { 34 public void paint(Graphics2D g) { 35 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 36 RenderingHints.VALUE_ANTIALIAS_ON); 37 38 g.setPaint(Color.black); 40 g.setFont(new Font("Times New Roman", Font.PLAIN, 20)); 41 g.drawString("Hello SVG drawString(...)", 20, 40); 42 43 g.translate(0, 70); 44 45 Ellipse2D ellipse = new Ellipse2D.Float(20, 0, 60, 60); 47 g.setPaint(new Color(176, 22, 40)); 48 g.fill(ellipse); 49 g.translate(60, 0); 50 g.setPaint(new Color(208, 170, 119)); 51 g.fill(ellipse); 52 g.translate(60, 0); 53 g.setPaint(new Color(221, 229, 111)); 54 g.fill(ellipse); 55 g.translate(60, 0); 56 g.setPaint(new Color(240, 165, 0)); 57 g.fill(ellipse); 58 59 g.translate(-180, 60); 60 61 BufferedImage pattern = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 63 Graphics2D ig = pattern.createGraphics(); 64 ig.setPaint(Color.white); 65 ig.fillRect(0, 0, 10, 10); 66 ig.setPaint(new Color(0xaaaaaa)); 67 ig.fillRect(0, 0, 5, 5); 68 ig.fillRect(5, 5, 5, 50); 69 TexturePaint texture = new TexturePaint(pattern, new Rectangle(0, 0, 10, 10)); 70 71 BufferedImage image = new BufferedImage(200, 150, BufferedImage.TYPE_INT_ARGB); 73 ig = image.createGraphics(); 74 ig.setPaint(texture); 75 ig.fillRect(0, 0, 200, 150); 76 g.drawImage(image, 40, 40, null); 77 78 image = new BufferedImage(200, 150, BufferedImage.TYPE_INT_ARGB); 79 ig = image.createGraphics(); 80 GradientPaint paint = new GradientPaint(0, 0, new Color(103, 103, 152), 81 200, 150, new Color(103, 103, 152, 0)); 82 ig.setPaint(paint); 83 ig.fillRect(0, 0, 200, 150); 84 ig.setPaint(Color.black); 85 ig.setFont(new Font("Arial", Font.PLAIN, 10)); 86 ig.drawString("This is an image with alpha", 10, 30); 87 ig.dispose(); 88 89 g.drawImage(image, 40, 40, null); 90 } 91 } 92 | Popular Tags |