Class DefaultResizerFactory
- java.lang.Object
-
- net.coobird.thumbnailator.resizers.DefaultResizerFactory
-
- All Implemented Interfaces:
ResizerFactory
public class DefaultResizerFactory extends java.lang.Object implements ResizerFactory
This class provides factory methods which provides suitableResizers for a given situation.Resizers returned by thisResizerFactory:-
The
Resizers returned by thisResizerFactorydepends on the size of the source and destination images. The conditions and theResizers returned are as follows:- Default via
getResizer() - Destination image has the same dimensions as the source image via
getResizer(Dimension, Dimension) - Both the width and height of the destination image is larger than the
source image via
getResizer(Dimension, Dimension) - Both the width and height of the destination image is smaller in the
source image by a factor larger than 2,
via
getResizer(Dimension, Dimension) - Both the width and height of the destination image is smaller in the
source image not by a factor larger than 2,
via
getResizer(Dimension, Dimension) - Other conditions not described via
getResizer(Dimension, Dimension)
- Default via
- Usage:
-
The following example code demonstrates how to use
DefaultResizerFactoryin order to obtain the optimalResizer, and using that in order to perform the resizing operation.BufferedImage sourceImage = new BufferedImageBuilder(400, 400).build(); BufferedImage destImage = new BufferedImageBuilder(200, 200).build(); Dimension sourceSize = new Dimension(sourceImage.getWidth(), sourceImage.getHeight()); Dimension destSize = new Dimension(destImage.getWidth(), destImage.getHeight()); // Obtain the optimal Resizer for this resizing operation. Resizer resizer = DefaultResizerFactory.getInstance().getResizer(sourceSize, destSize); // Perform the resizing using the Resizer obtained from the ResizerFactory. resizer.resize(sourceImage, destImage);
When a specific
Resizeris required, theResizersenumis another way to obtainResizers.- Since:
- 0.4.0
- See Also:
Resizers
-
-
Field Summary
Fields Modifier and Type Field Description private static DefaultResizerFactoryINSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description privateDefaultResizerFactory()This class is not intended to be instantiated via the constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ResizerFactorygetInstance()Returns an instance of this class.ResizergetResizer()Returns the defaultResizer.ResizergetResizer(java.awt.Dimension originalSize, java.awt.Dimension thumbnailSize)Returns a suitableResizer, given theDimensions of the original image and the thumbnail image.
-
-
-
Field Detail
-
INSTANCE
private static final DefaultResizerFactory INSTANCE
-
-
Method Detail
-
getInstance
public static ResizerFactory getInstance()
Returns an instance of this class.- Returns:
- An instance of this class.
-
getResizer
public Resizer getResizer()
Description copied from interface:ResizerFactoryReturns the defaultResizer.- Specified by:
getResizerin interfaceResizerFactory- Returns:
- The default
Resizer.
-
getResizer
public Resizer getResizer(java.awt.Dimension originalSize, java.awt.Dimension thumbnailSize)
Description copied from interface:ResizerFactoryReturns a suitableResizer, given theDimensions of the original image and the thumbnail image.- Specified by:
getResizerin interfaceResizerFactory- Parameters:
originalSize- The size of the original image.thumbnailSize- The size of the thumbnail.- Returns:
- The suitable
Resizerto perform the resizing operation for the given condition.
-
-