Class DimensionConstrain

java.lang.Object
com.mortennobel.imagescaling.DimensionConstrain

public class DimensionConstrain extends Object
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 Details

    • DimensionConstrain

      protected DimensionConstrain()
  • Method Details

    • getDimension

      public Dimension getDimension(Dimension dimension)
      Will always return a dimension with positive width and height;
      Parameters:
      dimension - of the unscaled image
      Returns:
      the dimension of the scaled image
    • createAbsolutionDimension

      public static DimensionConstrain createAbsolutionDimension(int width, int height)
      Used when the destination size is fixed. This may not keep the image aspect radio
      Parameters:
      width - destination dimension width
      height - destination dimension height
      Returns:
      destination dimension (width x height)
    • createRelativeDimension

      public static DimensionConstrain createRelativeDimension(float fraction)
      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

      public static DimensionConstrain createRelativeDimension(float fractionWidth, float fractionHeight)
      Used when the destination size is relative to the source. This keeps the image aspect radio if fractionWidth equals fractionHeight
      Returns:
    • createMaxDimension

      public static DimensionConstrain createMaxDimension(int width, int height)
      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

      public static DimensionConstrain createMaxDimensionNoOrientation(int length1, int length2)
      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: