Package org.tinfour.utils.rendering
Class RenderingSurfaceAid
- java.lang.Object
-
- org.tinfour.utils.rendering.RenderingSurfaceAid
-
public class RenderingSurfaceAid extends Object
Creates data elements suitable for rendering 2D graphics based on a Cartesian coordinate system. This class establishes a BufferedImage and associated Graphics2D object, as well as the appropriate coordinate transforms. Applications that require only the transform data may use the companion utility RenderingTransformAid.
-
-
Constructor Summary
Constructors Constructor Description RenderingSurfaceAid(int width, int height, int pad, double x0, double y0, double x1, double y1)Constructs a graphics surface (BufferedImage) and resources for a coordinate system appropriate for the presentation of a rectangular region defined by the specified coordinates.RenderingSurfaceAid(int width, int height, int pad, double x0, double y0, double x1, double y1, boolean alpha)Constructs a graphics surface (BufferedImage) and resources for a coordinate system appropriate for the presentation of a rectangular region defined by the specified coordinates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddrawFrame(Color c)Draws a 1-pixel rectangular frame around the outer boundaries of the rendering surface in the specified color.voidfillBackground(Color c)Fills the overall image with the specified colorBufferedImagegetBufferedImage()Gets the buffered image associated with this drawing surfaceAffineTransformgetCartesianToPixelTransform()Gets the affine transform for mapping Cartesian coordinates to pixel coordinates.Rectangle2DgetDomainRectangle()Gets the rectangle for the drawing area corresponding to the coordinate domain that was specified for the constructor.Graphics2DgetGraphics2D()Get the Graphics2D object associated with this drawing surface.doublegetPixelsPerUnit()Gets the distance in pixels across one unit of distance in the Cartesian coordinate system.AffineTransformgetPixelToCartesianTransform()Gets the affine transform for mapping pixel coordinates to Cartesian coordinates.doublegetUnitsPerPixel()Gets the distance across a pixel in the corresponding Cartesian coordinate system.
-
-
-
Constructor Detail
-
RenderingSurfaceAid
public RenderingSurfaceAid(int width, int height, int pad, double x0, double y0, double x1, double y1)Constructs a graphics surface (BufferedImage) and resources for a coordinate system appropriate for the presentation of a rectangular region defined by the specified coordinates. The transforms created by this class will be appropriate for drawing graphs within the coordinate domain as large as possible within the bounds of the specified size of the graphics surface based on width, height, and padding allowance.Some implementations of the of Java API's ImageIO do not support creating JPEG image files from a BufferedImage with an alpha channel When using this class with Java ImageIO to write JPEG images, the associated BufferedImage should be created without an alpha channel. An alternate constructor is provided for this purpose.
- Parameters:
width- the width of the drawing surface, in pixelsheight- the height of the drawing surface, in pixelspad- an arbitrary padding to be added to each side of the rectangle, in pixelsx0- Cartesian x coordinate for the lower-left corner of the domainy0- Cartesian y coordinate for the lower-left corner of the domainx1- Cartesian x coordinate for the upper-right corner of the domainy1- Cartesian y coordinate for the upper-right corner of the domain
-
RenderingSurfaceAid
public RenderingSurfaceAid(int width, int height, int pad, double x0, double y0, double x1, double y1, boolean alpha)Constructs a graphics surface (BufferedImage) and resources for a coordinate system appropriate for the presentation of a rectangular region defined by the specified coordinates. The transforms created by this class will be appropriate for drawing graphs within the coordinate domain as large as possible within the bounds of the specified size of the graphics surface based on width, height, and padding allowance.When using this class with Java ImageIO to write JPEG images, the associated BufferedImage should be created without an alpha channel. Some implementations of the of Java API's ImageIO do not support creating JPEG image files from a BufferedImage with an alpha channel.
- Parameters:
width- the width of the drawing surface, in pixelsheight- the height of the drawing surface, in pixelspad- an arbitrary padding to be added to each side of the rectangle, in pixelsx0- Cartesian x coordinate for the lower-left corner of the domainy0- Cartesian y coordinate for the lower-left corner of the domainx1- Cartesian x coordinate for the upper-right corner of the domainy1- Cartesian y coordinate for the upper-right corner of the domainalpha- indicates if the associated image should be created using an alpha channel.
-
-
Method Detail
-
getCartesianToPixelTransform
public AffineTransform getCartesianToPixelTransform()
Gets the affine transform for mapping Cartesian coordinates to pixel coordinates. The transform was established by the constructor for this class.- Returns:
- a valid instance of an affine transform
-
getPixelToCartesianTransform
public AffineTransform getPixelToCartesianTransform()
Gets the affine transform for mapping pixel coordinates to Cartesian coordinates. The transform was established by the constructor for this class.- Returns:
- a valid instance of an affine transform
-
getDomainRectangle
public Rectangle2D getDomainRectangle()
Gets the rectangle for the drawing area corresponding to the coordinate domain that was specified for the constructor. This rectangle is suitable for use as a clipping rectangle when creating images.- Returns:
- a valid instance of a rectangle, in pixel coordinates.
-
getBufferedImage
public BufferedImage getBufferedImage()
Gets the buffered image associated with this drawing surface- Returns:
- a valid instance of a buffered image
-
getGraphics2D
public Graphics2D getGraphics2D()
Get the Graphics2D object associated with this drawing surface.- Returns:
- a valid instance of a graphics object.
-
getUnitsPerPixel
public double getUnitsPerPixel()
Gets the distance across a pixel in the corresponding Cartesian coordinate system.- Returns:
- a non-zero floating point value
-
getPixelsPerUnit
public double getPixelsPerUnit()
Gets the distance in pixels across one unit of distance in the Cartesian coordinate system.- Returns:
- a non-zero floating point value
-
fillBackground
public void fillBackground(Color c)
Fills the overall image with the specified color- Parameters:
c- a valid instance.
-
drawFrame
public void drawFrame(Color c)
Draws a 1-pixel rectangular frame around the outer boundaries of the rendering surface in the specified color.- Parameters:
c- a valid instance.
-
-