1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.GradientPaint ; 22 import java.awt.Graphics2D ; 23 import java.awt.Paint ; 24 import java.awt.Rectangle ; 25 import java.awt.RenderingHints ; 26 import java.awt.TexturePaint ; 27 import java.awt.image.BufferedImage ; 28 29 37 public class Paints implements Painter { 38 public void paint(Graphics2D g) { 39 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 40 RenderingHints.VALUE_ANTIALIAS_ON); 41 42 Paint defaultPaint = Color.black; 44 g.setPaint(defaultPaint); 45 46 g.translate(0, 30); 47 48 Rectangle rect = new Rectangle (10, 20, 100, 60); 51 52 Color fillColor = new Color (255, 255, 0, 128); 54 g.drawString("Semi transparent black", 10, 10); 55 g.drawString("Behind Rectangle", 40, 60); 56 g.setPaint(fillColor); 57 g.fill(rect); 58 59 g.translate(0, 90); 60 61 GradientPaint fillGradient = new GradientPaint (10, 20, Color.red, 63 110, 80, Color.yellow); 64 g.setPaint(defaultPaint); 65 g.drawString("Red to Yellow linear gradient", 10, 10); 66 g.setPaint(fillGradient); 67 g.fill(rect); 68 69 g.translate(0, 90); 70 71 BufferedImage buf = new BufferedImage (20, 20, BufferedImage.TYPE_INT_RGB); 73 Graphics2D bg = buf.createGraphics(); 74 bg.setPaint(Color.red); 75 bg.fillRect(0, 0, 10, 10); 76 bg.setPaint(Color.yellow); 77 bg.fillRect(10, 10, 10, 10); 78 bg.dispose(); 79 TexturePaint fillTexture = new TexturePaint (buf, new Rectangle (10, 20, 20, 20)); 80 g.setPaint(defaultPaint); 81 g.drawString("Texture Paint", 10, 10); 82 g.setPaint(fillTexture); 83 g.fill(rect); 84 } 85 } 86 | Popular Tags |