Package com.mortennobel.imagescaling
Class DimensionConstrain
java.lang.Object
com.mortennobel.imagescaling.DimensionConstrain
This class let you create dimension constrains based on a actual image.
Class may be subclassed to create user defined behavior. To do this you need to overwrite
the method getDimension(Dimension).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DimensionConstrain
createAbsolutionDimension
(int width, int height) Used when the destination size is fixed.static DimensionConstrain
createMaxDimension
(int width, int height) Forces the image to keep radio and be keeped within the width and heightstatic DimensionConstrain
createMaxDimension
(int width, int height, boolean neverEnlargeImage) Forces the image to keep radio and be keeped within the width and height.static DimensionConstrain
createMaxDimensionNoOrientation
(int length1, int length2) Forces the image to keep radio and be keeped within the width and height.static DimensionConstrain
createMaxDimensionNoOrientation
(int length1, int length2, boolean neverEnlargeImage) Forces the image to keep radio and be keeped within the width and height.static DimensionConstrain
createRelativeDimension
(float fraction) Used when the destination size is relative to the source.static DimensionConstrain
createRelativeDimension
(float fractionWidth, float fractionHeight) Used when the destination size is relative to the source.getDimension
(Dimension dimension) Will always return a dimension with positive width and height;
-
Constructor Details
-
DimensionConstrain
protected DimensionConstrain()
-
-
Method Details
-
getDimension
Will always return a dimension with positive width and height;- Parameters:
dimension
- of the unscaled image- Returns:
- the dimension of the scaled image
-
createAbsolutionDimension
Used when the destination size is fixed. This may not keep the image aspect radio- Parameters:
width
- destination dimension widthheight
- destination dimension height- Returns:
- destination dimension (width x height)
-
createRelativeDimension
Used when the destination size is relative to the source. This keeps the image aspect radio- Parameters:
fraction
- resize fraction (must be a positive number)- Returns:
- the new dimension (the input dimension times the fraction)
-
createRelativeDimension
Used when the destination size is relative to the source. This keeps the image aspect radio if fractionWidth equals fractionHeight- Returns:
-
createMaxDimension
Forces the image to keep radio and be keeped within the width and height- Parameters:
width
-height
-- Returns:
-
createMaxDimension
public static DimensionConstrain createMaxDimension(int width, int height, boolean neverEnlargeImage) Forces the image to keep radio and be keeped within the width and height.- Parameters:
width
-height
-neverEnlargeImage
- if true only a downscale will occour- Returns:
-
createMaxDimensionNoOrientation
Forces the image to keep radio and be keeped within the width and height. Width and height are defined (length1 x length2) or (length2 x length1). This is usefull is the scaling allow a certain format (such as 16x9") but allow the dimension to be rotated 90 degrees (so also 9x16" is allowed).- Parameters:
length1
-length2
-- Returns:
-
createMaxDimensionNoOrientation
public static DimensionConstrain createMaxDimensionNoOrientation(int length1, int length2, boolean neverEnlargeImage) Forces the image to keep radio and be keeped within the width and height. Width and height are defined (length1 x length2) or (length2 x length1). This is usefull is the scaling allow a certain format (such as 16x9") but allow the dimension to be rotated 90 degrees (so also 9x16" is allowed).- Parameters:
length1
-length2
-neverEnlargeImage
- if true only a downscale will occour- Returns:
-