Module java.desktop
Package java.awt

Class TexturePaint

java.lang.Object
java.awt.TexturePaint
All Implemented Interfaces:
Paint, Transparency

public class TexturePaint
extends Object
implements Paint
The TexturePaint class provides a way to fill a Shape with a texture that is specified as a 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 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.
See Also:
Paint, Graphics2D.setPaint(java.awt.Paint)
  • Constructor Details

    • TexturePaint

      public TexturePaint​(BufferedImage txtr, Rectangle2D anchor)
      Constructs a TexturePaint object.
      Parameters:
      txtr - the BufferedImage object with the texture used for painting
      anchor - the Rectangle2D in user space used to anchor and replicate the texture
  • Method Details

    • getImage

      public BufferedImage getImage()
      Returns the BufferedImage texture used to fill the shapes.
      Returns:
      a BufferedImage.
    • getAnchorRect

      public Rectangle2D getAnchorRect()
      Returns a copy of the anchor rectangle which positions and sizes the textured image.
      Returns:
      the Rectangle2D used to anchor and size this TexturePaint.
    • createContext

      public PaintContext createContext​(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
      Creates and returns a PaintContext used to generate a tiled image pattern. See the specification of the method in the Paint interface for information on null parameter handling.
      Specified by:
      createContext in interface Paint
      Parameters:
      cm - the preferred ColorModel which represents the most convenient format for the caller to receive the pixel data, or null if there is no preference.
      deviceBounds - the device space bounding box of the graphics primitive being rendered.
      userBounds - the user space bounding box of the graphics primitive being rendered.
      xform - the AffineTransform from user space into device space.
      hints - the set of hints that the context object can use to choose between rendering alternatives.
      Returns:
      the PaintContext for generating color patterns.
      See Also:
      Paint, PaintContext, ColorModel, Rectangle, Rectangle2D, AffineTransform, RenderingHints
    • getTransparency

      public int getTransparency()
      Returns the transparency mode for this TexturePaint.
      Specified by:
      getTransparency in interface Transparency
      Returns:
      the transparency mode for this TexturePaint as an integer value.
      See Also:
      Transparency