TexturePaintpublic class TexturePaint extends Object implements PaintThe TexturePaint class provides a way to fill a
{@link Shape} with a texture that is specified as
a {@link BufferedImage}. The size of the BufferedImage
object should be small because the BufferedImage data
is copied by the TexturePaint object.
At construction time, the texture is anchored to the upper
left corner of a {@link Rectangle2D} that is
specified in user space. Texture is computed for
locations in the device space by conceptually replicating the
specified Rectangle2D infinitely in all directions
in user space and mapping the BufferedImage to each
replicated Rectangle2D . |
Fields Summary |
---|
BufferedImage | bufImg | double | tx | double | ty | double | sx | double | sy |
Constructors Summary |
---|
public TexturePaint(BufferedImage txtr, Rectangle2D anchor)Constructs a TexturePaint object.
this.bufImg = txtr;
this.tx = anchor.getX();
this.ty = anchor.getY();
this.sx = anchor.getWidth() / bufImg.getWidth();
this.sy = anchor.getHeight() / bufImg.getHeight();
|
Methods Summary |
---|
public java.awt.PaintContext | createContext(java.awt.image.ColorModel cm, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints)Creates and returns a context used to generate the color pattern.
if (xform == null) {
xform = new AffineTransform();
} else {
xform = (AffineTransform) xform.clone();
}
xform.translate(tx, ty);
xform.scale(sx, sy);
return TexturePaintContext.getContext(bufImg, xform, hints,
deviceBounds);
| public java.awt.geom.Rectangle2D | getAnchorRect()Returns a copy of the anchor rectangle which positions and
sizes the textured image.
return new Rectangle2D.Double(tx, ty,
sx * bufImg.getWidth(),
sy * bufImg.getHeight());
| public java.awt.image.BufferedImage | getImage()Returns the BufferedImage texture used to
fill the shapes.
return bufImg;
| public int | getTransparency()Returns the transparency mode for this TexturePaint .
return (bufImg.getColorModel()).getTransparency();
|
|