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 specificdimensionsandpreserveAspectRatio. -
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>).booleanIf true, the ratio between x and y is kept constant when scaling.voidsetDimensions(DimensionsProvider dimensions) The dimensions the source image/entity is desired to be scaled to.voidsetDimensionsSourceFallback(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>).voidsetPreserveAspectRatio(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, onInitializationMethods 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 specificdimensionsandpreserveAspectRatio.- 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:ScaleCalculatorCalculates a scaling-factor for a source image/entity of particular dimensions.- Specified by:
calculatein 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
dimensionsTargetand 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
dimensionsTargetand the the smaller dimension is guaranteed to be equal to or lesser than its equivalent indimensionsTarget.
-