Package com.openhtmltopdf.util
Class ScalingOptions
- java.lang.Object
-
- com.openhtmltopdf.util.ScalingOptions
-
public class ScalingOptions extends java.lang.Object
POJO used when callingImageUtil.getScaledInstance(ScalingOptions,java.awt.image.BufferedImage)
. Encapsulates a set of parameters related to scaling quality and output. Values are final once constructed, except for target width and height, which can be change and the options instance reused. There is a default constructor for average quality and performance.
-
-
Field Summary
Fields Modifier and Type Field Description private DownscaleQuality
downscalingHint
private java.lang.Object
renderingHint
private int
targetHeight
private int
targetWidth
-
Constructor Summary
Constructors Constructor Description ScalingOptions()
Default scaling options, nearest neighbor interpolation, and fast downscaling.ScalingOptions(int targetWidth, int targetHeight, int type, DownscaleQuality downscalingHint, java.lang.Object hint)
Constructor with all options.ScalingOptions(DownscaleQuality downscalingHint, java.lang.Object interpolationHint)
Constructor with all options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyRenderingHints(java.awt.Graphics2D g2)
Applies any rendering hints configured for these ScalingOptions to a Graphics2D instance before image operations are called on it.DownscaleQuality
getDownscalingHint()
java.lang.Object
getRenderingHint()
protected java.util.Map<java.awt.RenderingHints.Key,java.lang.Object>
getRenderingHints()
Returns a Map of image rendering hints applicable toGraphics2D.setRenderingHints(java.util.Map)
.int
getTargetHeight()
int
getTargetWidth()
void
setTargetDimensions(java.awt.Dimension dim)
void
setTargetHeight(int targetHeight)
void
setTargetWidth(int targetWidth)
boolean
sizeMatches(int w, int h)
Returns true if the target size specified by these options matches the size provided (e.g.boolean
sizeMatches(java.awt.Image img)
Returns true if the target size specified by these options matches the size provided (e.g.
-
-
-
Field Detail
-
downscalingHint
private DownscaleQuality downscalingHint
-
renderingHint
private java.lang.Object renderingHint
-
targetWidth
private int targetWidth
-
targetHeight
private int targetHeight
-
-
Constructor Detail
-
ScalingOptions
public ScalingOptions(DownscaleQuality downscalingHint, java.lang.Object interpolationHint)
Constructor with all options.- Parameters:
downscalingHint
- Directs downscaling quality. One of the enumerated types ofDownscaleQuality
such asDownscaleQuality.FAST
.interpolationHint
- Hint for interpolation to AWT image renderer, one of the Object constants fromRenderingHints
usingRenderingHints.KEY_INTERPOLATION
-
ScalingOptions
public ScalingOptions()
Default scaling options, nearest neighbor interpolation, and fast downscaling. This is fast, but not great quality.
-
ScalingOptions
public ScalingOptions(int targetWidth, int targetHeight, int type, DownscaleQuality downscalingHint, java.lang.Object hint)
Constructor with all options.- Parameters:
targetWidth
- Target width in pixels of image once scaledtargetHeight
- Target height in pixels of image once scaledtype
- Type ofBufferedImage
to create for output; see docs forBufferedImage(int,int,int)
downscalingHint
- Directs downscaling quality. One of the enumerated types ofDownscaleQuality
such asDownscaleQuality.FAST
.hint
- Hint for interpolation to AWT image renderer, one of the Object constants fromRenderingHints
usingRenderingHints.KEY_INTERPOLATION
-
-
Method Detail
-
getDownscalingHint
public DownscaleQuality getDownscalingHint()
- Returns:
- the current scaling hint
-
getRenderingHint
public java.lang.Object getRenderingHint()
- Returns:
- the current rendering hint
-
applyRenderingHints
public void applyRenderingHints(java.awt.Graphics2D g2)
Applies any rendering hints configured for these ScalingOptions to a Graphics2D instance before image operations are called on it. These might be- Parameters:
g2
- A Graphics2D instance on which scaled images will be rendered.
-
getRenderingHints
protected java.util.Map<java.awt.RenderingHints.Key,java.lang.Object> getRenderingHints()
Returns a Map of image rendering hints applicable toGraphics2D.setRenderingHints(java.util.Map)
. By default, this will only include the interpolation hint specified for this ScalingOptions. Other hints could be added in a overridden version in a subclass.- Returns:
- Map of rendering hints.
-
sizeMatches
public boolean sizeMatches(int w, int h)
Returns true if the target size specified by these options matches the size provided (e.g. image is already at target size).- Parameters:
w
- an image widthh
- an image height- Returns:
- true if image dimensions already match target size
-
sizeMatches
public boolean sizeMatches(java.awt.Image img)
Returns true if the target size specified by these options matches the size provided (e.g. image is already at target size).- Parameters:
img
-- Returns:
- true if image dimensions already match target size
-
getTargetWidth
public int getTargetWidth()
-
getTargetHeight
public int getTargetHeight()
-
setTargetWidth
public void setTargetWidth(int targetWidth)
-
setTargetHeight
public void setTargetHeight(int targetHeight)
-
setTargetDimensions
public void setTargetDimensions(java.awt.Dimension dim)
-
-