1 7 8 package java.awt; 9 10 import java.awt.geom.Rectangle2D ; 11 import java.awt.geom.AffineTransform ; 12 import java.awt.image.AffineTransformOp ; 13 import java.awt.image.BufferedImage ; 14 import java.awt.image.ColorModel ; 15 16 33 34 public class TexturePaint implements Paint { 35 36 BufferedImage bufImg; 37 double tx; 38 double ty; 39 double sx; 40 double sy; 41 42 49 public TexturePaint(BufferedImage txtr, 50 Rectangle2D anchor) { 51 this.bufImg = txtr; 52 this.tx = anchor.getX(); 53 this.ty = anchor.getY(); 54 this.sx = anchor.getWidth() / bufImg.getWidth(); 55 this.sy = anchor.getHeight() / bufImg.getHeight(); 56 } 57 58 63 public BufferedImage getImage() { 64 return bufImg; 65 } 66 67 73 public Rectangle2D getAnchorRect() { 74 return new Rectangle2D.Double (tx, ty, 75 sx * bufImg.getWidth(), 76 sy * bufImg.getHeight()); 77 } 78 79 95 public PaintContext createContext(ColorModel cm, 96 Rectangle deviceBounds, 97 Rectangle2D userBounds, 98 AffineTransform xform, 99 RenderingHints hints) { 100 if (xform == null) { 101 xform = new AffineTransform (); 102 } else { 103 xform = (AffineTransform ) xform.clone(); 104 } 105 xform.translate(tx, ty); 106 xform.scale(sx, sy); 107 108 return TexturePaintContext.getContext(bufImg, xform, hints, 109 deviceBounds); 110 } 111 112 118 public int getTransparency() { 119 return (bufImg.getColorModel()).getTransparency(); 120 } 121 122 } 123 124 | Popular Tags |