com.smartwerkz.jupload.classic.image
Class ImageUtil

java.lang.Object
  extended by com.smartwerkz.jupload.classic.image.ImageUtil

public class ImageUtil
extends java.lang.Object

Utility methods for image processing // TODO: make it possible to add/change metadata for testfiles

Since:
27.05.2005
Author:
Mike Haller, Dominik Seifert

Field Summary
static int POSITION_BOTTOM_LEFT
           
static int POSITION_BOTTOM_RIGHT
           
static int POSITION_CENTER
           
static int POSITION_TOP_LEFT
           
static int POSITION_TOP_RIGHT
           
static java.util.List readableFormats
           
static java.util.List writableFormats
           
 
Constructor Summary
ImageUtil()
           
 
Method Summary
static void cacheBytes(ImageData data, java.lang.String outputFormat)
           
static void cacheFormats()
          (Re)Cache all readable and writable formats in the readableFormats and writableFormats lists.
static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage img, int w, int h, java.lang.Object interpolationHint)
          Copies the given image where the result will have the given size.
static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage img, int w, int h, java.lang.Object interpolationHint, int type)
          Copies the given image where the result will have the given size.
static java.awt.image.BufferedImage copyScaled(java.awt.image.BufferedImage img, int maxw, int maxh, boolean smooth)
          Copies the given image with the specified bounds and releases the original's resources.
static java.awt.image.BufferedImage createMergedImage(java.awt.image.BufferedImage img, java.awt.Image innerImage, int pos)
           
static ImageData getCachedData(java.awt.image.BufferedImage img, java.lang.String format)
          Creates and returns a new ImageData object, containing the given image and its bytes, encoded with the given format.
static java.util.Iterator getImageReadersBySuffix(java.lang.String suffix)
           
static boolean isReadableImage(java.io.File file)
           
static boolean isReadableImageExtension(java.lang.String ext)
           
static boolean isReadableImageName(java.lang.String name)
           
static boolean isWritableImageExtension(java.lang.String ext)
           
static boolean needsCacheOrConversion(UploadFile file, int maxw, int maxh, boolean inclMetadata, java.lang.String outputFormat, java.awt.Dimension dimensionFilter)
          Indicates wether caching or conversion is needed.
static java.awt.image.BufferedImage readImage(java.io.File file)
          Creates and returns a new BufferedImage from the given file using the file's extension as format.
static java.awt.image.BufferedImage readImage(java.io.InputStream stream, java.lang.String name)
          Creates and returns a new BufferedImage from the given stream using the name's extension as format.
static java.awt.image.BufferedImage readImage(java.net.URL url)
          Creates and returns a new BufferedImage from the given URL using the url's extension as format.
static ImageData readImageData(java.io.File file, boolean inclMetadata, boolean cacheBytes)
          Creates and returns an ImageData object, containing the picture and -if wanted and available- its metadata.
static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img, int maxw, int maxh)
           
static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img, int maxw, int maxh, boolean smooth)
           
static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img, int maxw, int maxh, java.lang.Object interpolationHint)
          If necessary or specified, copies the given image with the specified bounds.
static java.awt.Point translatePosition(java.awt.Dimension contSize, java.awt.Dimension innerSize, int posType)
          Returns the position of the inner object with the given size, according to the posType within the dimensions of w and h.
static java.awt.Point translatePosition(int w, int h, int innerW, int innerH, int posType)
          Returns the position of the inner object with the given size, according to the posType within the dimensions of w and h.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_CENTER

public static final int POSITION_CENTER
See Also:
Constant Field Values

POSITION_TOP_LEFT

public static final int POSITION_TOP_LEFT
See Also:
Constant Field Values

POSITION_TOP_RIGHT

public static final int POSITION_TOP_RIGHT
See Also:
Constant Field Values

POSITION_BOTTOM_LEFT

public static final int POSITION_BOTTOM_LEFT
See Also:
Constant Field Values

POSITION_BOTTOM_RIGHT

public static final int POSITION_BOTTOM_RIGHT
See Also:
Constant Field Values

readableFormats

public static final java.util.List readableFormats

writableFormats

public static final java.util.List writableFormats
Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

needsCacheOrConversion

public static boolean needsCacheOrConversion(UploadFile file,
                                             int maxw,
                                             int maxh,
                                             boolean inclMetadata,
                                             java.lang.String outputFormat,
                                             java.awt.Dimension dimensionFilter)
Indicates wether caching or conversion is needed. If a dimensionFilter or maxResizeWidth or -height has been specified, it will return true only if there is no information in the global image cache or the image information require resizing.


readImage

public static java.awt.image.BufferedImage readImage(java.io.File file)
                                              throws java.io.IOException
Creates and returns a new BufferedImage from the given file using the file's extension as format.

Throws:
java.io.IOException

readImage

public static java.awt.image.BufferedImage readImage(java.net.URL url)
                                              throws java.io.IOException
Creates and returns a new BufferedImage from the given URL using the url's extension as format.

Throws:
java.io.IOException

readImage

public static java.awt.image.BufferedImage readImage(java.io.InputStream stream,
                                                     java.lang.String name)
                                              throws java.io.IOException
Creates and returns a new BufferedImage from the given stream using the name's extension as format.

Throws:
java.io.IOException

readImageData

public static ImageData readImageData(java.io.File file,
                                      boolean inclMetadata,
                                      boolean cacheBytes)
                               throws java.io.IOException
Creates and returns an ImageData object, containing the picture and -if wanted and available- its metadata. The rawdata will be null.

Throws:
java.io.IOException

getImageReadersBySuffix

public static java.util.Iterator getImageReadersBySuffix(java.lang.String suffix)

getCachedData

public static ImageData getCachedData(java.awt.image.BufferedImage img,
                                      java.lang.String format)
                               throws java.io.IOException
Creates and returns a new ImageData object, containing the given image and its bytes, encoded with the given format.

Throws:
java.io.IOException

cacheBytes

public static void cacheBytes(ImageData data,
                              java.lang.String outputFormat)
                       throws java.io.IOException
Throws:
java.io.IOException

copyScaled

public static java.awt.image.BufferedImage copyScaled(java.awt.image.BufferedImage img,
                                                      int maxw,
                                                      int maxh,
                                                      boolean smooth)
Copies the given image with the specified bounds and releases the original's resources.


resize

public static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img,
                                                  int maxw,
                                                  int maxh)

resize

public static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img,
                                                  int maxw,
                                                  int maxh,
                                                  boolean smooth)

resize

public static java.awt.image.BufferedImage resize(java.awt.image.BufferedImage img,
                                                  int maxw,
                                                  int maxh,
                                                  java.lang.Object interpolationHint)
If necessary or specified, copies the given image with the specified bounds. Releases the original's resources if copy is false. Keeps aspect ratio.


copyImage

public static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage img,
                                                     int w,
                                                     int h,
                                                     java.lang.Object interpolationHint)
Copies the given image where the result will have the given size. If the src image is smaller than the specified size, it will be drawn centered.


copyImage

public static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage img,
                                                     int w,
                                                     int h,
                                                     java.lang.Object interpolationHint,
                                                     int type)
Copies the given image where the result will have the given size. If the src image is smaller than the specified size, it will be drawn centered.


createMergedImage

public static java.awt.image.BufferedImage createMergedImage(java.awt.image.BufferedImage img,
                                                             java.awt.Image innerImage,
                                                             int pos)

translatePosition

public static java.awt.Point translatePosition(int w,
                                               int h,
                                               int innerW,
                                               int innerH,
                                               int posType)
Returns the position of the inner object with the given size, according to the posType within the dimensions of w and h.


translatePosition

public static java.awt.Point translatePosition(java.awt.Dimension contSize,
                                               java.awt.Dimension innerSize,
                                               int posType)
Returns the position of the inner object with the given size, according to the posType within the dimensions of w and h.


cacheFormats

public static void cacheFormats()
(Re)Cache all readable and writable formats in the readableFormats and writableFormats lists.


isReadableImage

public static boolean isReadableImage(java.io.File file)
Returns:
wether the given file has a readable image extension.

isReadableImageName

public static boolean isReadableImageName(java.lang.String name)
Returns:
wether the given filename has a readable image extension.

isReadableImageExtension

public static boolean isReadableImageExtension(java.lang.String ext)
Returns:
wether the given extension is readable.

isWritableImageExtension

public static boolean isWritableImageExtension(java.lang.String ext)
Returns:
wether the given extension is writable.


Copyright © 2007 smartwerkz.com. All Rights Reserved.