Class ToDimensions
Calculates a scaling-factor to make the source image have identical dimensions as
dimensionsTarget
.
If preserveAspectRatio
is true, then the aspect ratio is preserved, and both
dimensions may not be identical to dimensionsTarget
, but at least one will be, and the
other will not be exceed that of dimensionsTarget
.
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionToDimensions
(int sizeX, int sizeY) Create with specific lengths for X and Y dimensions.ToDimensions
(int sizeX, int sizeY, boolean preserveAspectRatio) Create with specific lengths for X and Y dimensions andpreserveAspectRatio
.ToDimensions
(DimensionsProvider dimensions) Create with specificdimensions
.ToDimensions
(DimensionsProvider dimensions, boolean preserveAspectRatio) Create with specificdimensions
andpreserveAspectRatio
. -
Method Summary
Modifier and TypeMethodDescriptioncalculate
(Optional<Dimensions> dimensionsToBeScaled, Optional<ImageSizeSuggestion> suggestedSize) Calculates a scaling-factor for a source image/entity of particular dimensions.The dimensions the source image/entity is desired to be scaled to.Source dimensions used as a fallback, if they are not passed as parameter tocalculate(java.util.Optional<org.anchoranalysis.image.core.dimensions.Dimensions>, java.util.Optional<org.anchoranalysis.image.core.dimensions.size.suggestion.ImageSizeSuggestion>)
.boolean
If true, the ratio between x and y is kept constant when scaling.void
setDimensions
(DimensionsProvider dimensions) The dimensions the source image/entity is desired to be scaled to.void
setDimensionsSourceFallback
(DimensionsProvider dimensionsSourceFallback) Source dimensions used as a fallback, if they are not passed as parameter tocalculate(java.util.Optional<org.anchoranalysis.image.core.dimensions.Dimensions>, java.util.Optional<org.anchoranalysis.image.core.dimensions.size.suggestion.ImageSizeSuggestion>)
.void
setPreserveAspectRatio
(boolean preserveAspectRatio) If true, the ratio between x and y is kept constant when scaling.Methods inherited from class org.anchoranalysis.bean.initializable.InitializableBean
getInitialization, getLogger, getPropertyInitializer, initialize, initializeRecursive, initRecursiveWithInitializer, isInitialized, onInitialization
Methods inherited from class org.anchoranalysis.bean.AnchorBean
checkMisconfigured, describeBean, describeChildren, duplicateBean, fields, findFieldsOfClass, getBeanName, getLocalPath, localise, toString
-
Constructor Details
-
ToDimensions
public ToDimensions(int sizeX, int sizeY) Create with specific lengths for X and Y dimensions.- Parameters:
sizeX
- the size of the X-dimension.sizeY
- the size of the X-dimension.
-
ToDimensions
Create with specificdimensions
.- Parameters:
dimensions
- the dimensions the source image/entity is desired to be scaled to.
-
ToDimensions
public ToDimensions(int sizeX, int sizeY, boolean preserveAspectRatio) Create with specific lengths for X and Y dimensions andpreserveAspectRatio
.- Parameters:
sizeX
- the size of the X-dimension.sizeY
- the size of the X-dimension.preserveAspectRatio
- if true, the ratio between x and y is kept constant when scaling.
-
ToDimensions
Create with specificdimensions
andpreserveAspectRatio
.- Parameters:
dimensions
- the dimensions the source image/entity is desired to be scaled to.preserveAspectRatio
- if true, the ratio between x and y is kept constant when scaling.
-
ToDimensions
public ToDimensions()
-
-
Method Details
-
calculate
public ScaleFactor calculate(Optional<Dimensions> dimensionsToBeScaled, Optional<ImageSizeSuggestion> suggestedSize) throws OperationFailedException Description copied from class:ScaleCalculator
Calculates a scaling-factor for a source image/entity of particular dimensions.- Specified by:
calculate
in classScaleCalculator
- Parameters:
dimensionsToBeScaled
- dimensions of the source image/entity that will be scaled, if they are known.suggestedSize
- a string suggesting dimensions to resize to or a scaling-factor.- Returns:
- the scaling-factor to use.
- Throws:
OperationFailedException
- if a scale-factor cannot be successfully calculated.
-
getDimensions
The dimensions the source image/entity is desired to be scaled to. -
setDimensions
The dimensions the source image/entity is desired to be scaled to. -
getDimensionsSourceFallback
Source dimensions used as a fallback, if they are not passed as parameter tocalculate(java.util.Optional<org.anchoranalysis.image.core.dimensions.Dimensions>, java.util.Optional<org.anchoranalysis.image.core.dimensions.size.suggestion.ImageSizeSuggestion>)
. -
setDimensionsSourceFallback
Source dimensions used as a fallback, if they are not passed as parameter tocalculate(java.util.Optional<org.anchoranalysis.image.core.dimensions.Dimensions>, java.util.Optional<org.anchoranalysis.image.core.dimensions.size.suggestion.ImageSizeSuggestion>)
. -
isPreserveAspectRatio
public boolean isPreserveAspectRatio()If true, the ratio between x and y is kept constant when scaling.The larger dimension is will be scaled to be the same as
dimensionsTarget
and the the smaller dimension is guaranteed to be equal to or lesser than its equivalent indimensionsTarget
. -
setPreserveAspectRatio
public void setPreserveAspectRatio(boolean preserveAspectRatio) If true, the ratio between x and y is kept constant when scaling.The larger dimension is will be scaled to be the same as
dimensionsTarget
and the the smaller dimension is guaranteed to be equal to or lesser than its equivalent indimensionsTarget
.
-