Dekoh platform API

dekoh.portal.fwk.image
Class AbstractImageResizer

java.lang.Object
  extended by dekoh.portal.fwk.image.AbstractImageResizer
All Implemented Interfaces:
ImageResizer
Direct Known Subclasses:
FastImageResizer

public abstract class AbstractImageResizer
extends Object
implements ImageResizer

A abstract implementation of ImageResizer that performs the common tasks of reading the image and writing the resized image. The sub-class is expected to provide the implementation for the real resizing algorithm in AbstractImageResizer.resizeImage(BufferedImage,int,int).

Since:
Jan 3, 2007

Nested Class Summary
static class AbstractImageResizer.ImageWithReader
           
 
Field Summary
 
Fields inherited from interface dekoh.portal.fwk.image.ImageResizer
DEFAULT_COMPRESSION_QUALITY
 
Constructor Summary
AbstractImageResizer()
           
 
Method Summary
 ImageReader getImageReader(ImageInputStream stream, File infile)
           
protected  int getImageType(BufferedImage image)
          Returns the type of the image for the given image.
 BufferedImage readImage(ImageReader reader, ImageInputStream stream)
           
 void resize(File infile, File outfile, float compressionQuality, int maxWidth, int maxHeight)
          Read an image from the input file, resize the image and write it to the destination file.
 void resize(File infile, File outfile, float compressionQuality, int maxWidth, int maxHeight, boolean square)
          Read an image from the input file, resize the image and write it to the destination file.
 void resize(File infile, File outfile, float compressionQuality, int maxWidth, int maxHeight, boolean square, EXIFOrientation photoOrientation)
          Read an image from the input file, resize the image and write it to the destination file.
 AbstractImageResizer.ImageWithReader resizeAndReturn(File infile, File outfile, float compressionQuality, int maxWidth, int maxHeight, boolean square, EXIFOrientation photoOrientation)
           
 BufferedImage resizeAndSaveBufferedImage(AbstractImageResizer.ImageWithReader bufferedImage, File outFile, float compressionQuality, int maxWidth, int maxHeight, boolean square)
           
abstract  BufferedImage resizeImage(BufferedImage origImage, int newWidth, int newHeight)
          The real implementation for image resizing to be provided by subclasses.
 BufferedImage resizeToSize(BufferedImage image, boolean square, int maxWidth, int maxHeight)
           
 BufferedImage toBufferedImage(BufferedImage origImage, int newWidth, int newHeight)
           
 BufferedImage toBufferedImage(Image origImage, int imageType, int newWidth, int newHeight)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractImageResizer

public AbstractImageResizer()
Method Detail

resize

public final void resize(File infile,
                         File outfile,
                         float compressionQuality,
                         int maxWidth,
                         int maxHeight)
                  throws IOException
Description copied from interface: ImageResizer
Read an image from the input file, resize the image and write it to the destination file. Similar to ImageResizer.resize(java.io.File,java.io.File,float,int,int,boolean,EXIFOrientation) with default value of square as false.

Specified by:
resize in interface ImageResizer
Throws:
IOException

resize

public final void resize(File infile,
                         File outfile,
                         float compressionQuality,
                         int maxWidth,
                         int maxHeight,
                         boolean square)
                  throws IOException
Description copied from interface: ImageResizer
Read an image from the input file, resize the image and write it to the destination file. Can optionally crop the image to a square.

Specified by:
resize in interface ImageResizer
Throws:
IOException

resize

public final void resize(File infile,
                         File outfile,
                         float compressionQuality,
                         int maxWidth,
                         int maxHeight,
                         boolean square,
                         EXIFOrientation photoOrientation)
                  throws IOException
Description copied from interface: ImageResizer
Read an image from the input file, resize the image and write it to the destination file. Can optionally crop the image to a square. Can compensate for an exif orientation in the photo ie the image will be rotated/mirrored to look right.

Specified by:
resize in interface ImageResizer
Throws:
IOException

resizeAndReturn

public final AbstractImageResizer.ImageWithReader resizeAndReturn(File infile,
                                                                  File outfile,
                                                                  float compressionQuality,
                                                                  int maxWidth,
                                                                  int maxHeight,
                                                                  boolean square,
                                                                  EXIFOrientation photoOrientation)
                                                           throws IOException
Throws:
IOException

resizeAndSaveBufferedImage

public final BufferedImage resizeAndSaveBufferedImage(AbstractImageResizer.ImageWithReader bufferedImage,
                                                      File outFile,
                                                      float compressionQuality,
                                                      int maxWidth,
                                                      int maxHeight,
                                                      boolean square)
                                               throws IOException
Throws:
IOException

resizeToSize

public BufferedImage resizeToSize(BufferedImage image,
                                  boolean square,
                                  int maxWidth,
                                  int maxHeight)

getImageReader

public ImageReader getImageReader(ImageInputStream stream,
                                  File infile)
                           throws IIOException
Throws:
IIOException

readImage

public BufferedImage readImage(ImageReader reader,
                               ImageInputStream stream)
                        throws IOException
Throws:
IOException

resizeImage

public abstract BufferedImage resizeImage(BufferedImage origImage,
                                          int newWidth,
                                          int newHeight)
The real implementation for image resizing to be provided by subclasses.

Parameters:
origImage - The image read from the file
newWidth - The width of the resized image in keeping with the aspect ratio
newHeight - The height of the resized image in keeping with the aspect ratio
Returns:
the resized image

toBufferedImage

public BufferedImage toBufferedImage(BufferedImage origImage,
                                     int newWidth,
                                     int newHeight)

toBufferedImage

public BufferedImage toBufferedImage(Image origImage,
                                     int imageType,
                                     int newWidth,
                                     int newHeight)

getImageType

protected int getImageType(BufferedImage image)
Returns the type of the image for the given image. Lookst at the given image's color model for hasAlpha and isAlphaPremultiplied and returns BufferedImage.TYPE_INT_ARGB_PRE or BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB accordingly.

Parameters:
image - The BufferedImage whose type needs to be found.
Returns:
int imageType

Dekoh platform API

© 2009 Pramati Technologies - Dekoh - Portal for Developers