com.mortennobel.imagescaling
Class DimensionConstrain

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

public class DimensionConstrain
extends java.lang.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 Summary
protected DimensionConstrain()
           
 
Method Summary
static 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 height
static 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.
 java.awt.Dimension getDimension(java.awt.Dimension dimension)
          Will always return a dimension with positive width and height;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DimensionConstrain

protected DimensionConstrain()
Method Detail

getDimension

public java.awt.Dimension getDimension(java.awt.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

Parameters:
-
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:


Copyright © 2010. All Rights Reserved.