Top Description Fields Constructors Methods
com.openhtmltopdf.util

public Class ScalingOptions

extends Object
Class Inheritance
Imports
java.awt.*, java.util.HashMap, .Map

POJO used when calling com.openhtmltopdf.util.ImageUtil#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

Modifier and TypeField and Description
private DownscaleQuality
private Object
private int
private int

Constructor Summary

AccessConstructor and Description
public
ScalingOptions(DownscaleQuality
Directs downscaling quality. One of the enumerated types of com.openhtmltopdf.util.DownscaleQuality such as com.openhtmltopdf.util.DownscaleQuality#FAST.
downscalingHint
,
Object
Hint for interpolation to AWT image renderer, one of the Object constants from java.awt.RenderingHints using java.awt.RenderingHints#KEY_INTERPOLATION
interpolationHint
)

Constructor with all options.

public
ScalingOptions()

Default scaling options, nearest neighbor interpolation, and fast downscaling.

public
ScalingOptions(int
Target width in pixels of image once scaled
targetWidth
,
int
Target height in pixels of image once scaled
targetHeight
,
int type, DownscaleQuality
Directs downscaling quality. One of the enumerated types of com.openhtmltopdf.util.DownscaleQuality such as com.openhtmltopdf.util.DownscaleQuality#FAST.
downscalingHint
,
Object
Hint for interpolation to AWT image renderer, one of the Object constants from java.awt.RenderingHints using java.awt.RenderingHints#KEY_INTERPOLATION
hint
)

Constructor with all options.

Method Summary

Modifier and TypeMethod and Description
public void
applyRenderingHints(Graphics2D
A Graphics2D instance on which scaled images will be rendered.
g2
)

Applies any rendering hints configured for these ScalingOptions to a Graphics2D instance before image operations are called on it.

public DownscaleQuality

Returns:

the current scaling hint
getDownscalingHint
()

public Object

Returns:

the current rendering hint
getRenderingHint
()

protected Map<RenderingHints.Key, Object>

Returns:

Map of rendering hints.
getRenderingHints
()

Returns a Map of image rendering hints applicable to Graphics2D#setRenderingHints(java.util.Map).

public int
public int
public void
public void
setTargetHeight(int targetHeight)

public void
setTargetWidth(int targetWidth)

public boolean

Returns:

true if image dimensions already match target size
sizeMatches
(int
an image width
w
,
int
an image height
h
)

Returns true if the target size specified by these options matches the size provided (e.g. image is already at target size).

public boolean

Returns:

true if image dimensions already match target size
sizeMatches
(Image img)

Returns true if the target size specified by these options matches the size provided (e.g. image is already at target size).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

downscalingHintback to summary
private DownscaleQuality downscalingHint
renderingHintback to summary
private Object renderingHint
targetHeightback to summary
private int targetHeight
targetWidthback to summary
private int targetWidth

Constructor Detail

ScalingOptionsback to summary
public ScalingOptions(DownscaleQuality downscalingHint, Object interpolationHint)

Constructor with all options.

Parameters
downscalingHint:DownscaleQuality

Directs downscaling quality. One of the enumerated types of com.openhtmltopdf.util.DownscaleQuality such as com.openhtmltopdf.util.DownscaleQuality#FAST.

interpolationHint:Object

Hint for interpolation to AWT image renderer, one of the Object constants from java.awt.RenderingHints using java.awt.RenderingHints#KEY_INTERPOLATION

ScalingOptionsback to summary
public ScalingOptions()

Default scaling options, nearest neighbor interpolation, and fast downscaling. This is fast, but not great quality.

ScalingOptionsback to summary
public ScalingOptions(int targetWidth, int targetHeight, int type, DownscaleQuality downscalingHint, Object hint)

Constructor with all options.

Parameters
targetWidth:int

Target width in pixels of image once scaled

targetHeight:int

Target height in pixels of image once scaled

type:int

Type of java.awt.image.BufferedImage to create for output; see docs for java.awt.image.BufferedImage#BufferedImage(int, int, int)

downscalingHint:DownscaleQuality

Directs downscaling quality. One of the enumerated types of com.openhtmltopdf.util.DownscaleQuality such as com.openhtmltopdf.util.DownscaleQuality#FAST.

hint:Object

Hint for interpolation to AWT image renderer, one of the Object constants from java.awt.RenderingHints using java.awt.RenderingHints#KEY_INTERPOLATION

Method Detail

applyRenderingHintsback to summary
public void applyRenderingHints(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:Graphics2D

A Graphics2D instance on which scaled images will be rendered.

getDownscalingHintback to summary
public DownscaleQuality getDownscalingHint()
Returns:DownscaleQuality

the current scaling hint

getRenderingHintback to summary
public Object getRenderingHint()
Returns:Object

the current rendering hint

getRenderingHintsback to summary
protected Map<RenderingHints.Key, Object> getRenderingHints()

Returns a Map of image rendering hints applicable to Graphics2D#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<RenderingHints.Key, Object>

Map of rendering hints.

getTargetHeightback to summary
public int getTargetHeight()
getTargetWidthback to summary
public int getTargetWidth()
setTargetDimensionsback to summary
public void setTargetDimensions(Dimension dim)
setTargetHeightback to summary
public void setTargetHeight(int targetHeight)
setTargetWidthback to summary
public void setTargetWidth(int targetWidth)
sizeMatchesback to summary
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:int

an image width

h:int

an image height

Returns:boolean

true if image dimensions already match target size

sizeMatchesback to summary
public boolean sizeMatches(Image img)

Returns true if the target size specified by these options matches the size provided (e.g. image is already at target size).

Returns:boolean

true if image dimensions already match target size