to.etc.sjit
Class ImaTool

java.lang.Object
  extended by to.etc.sjit.ImaTool

public class ImaTool
extends java.lang.Object

This static utility class has a lot of image-related helper functions.

Author:
Frits Jalvingh

Method Summary
static java.awt.image.BufferedImage awtLoadBufferedImage(java.io.File f)
          Loads the image from the file into an image.
static java.awt.Image awtLoadImage(java.io.File f)
          Loads the image from the file into an image.
static java.awt.image.BufferedImage awtResize(java.awt.image.BufferedImage bi, int w, int h)
          Resizes a BufferedImage while keeping it's aspect ratio, using the AWT mechanism...
static double findQualityBySize(java.awt.image.BufferedImage bi, int sizenear)
          Taking a BufferedImage, this function will try to find a JPEG quality factor that will save the image with a size around the size specified.
static java.awt.Image loadFile_image(java.io.File f)
          Loads an image from a file.
static java.awt.image.BufferedImage loadFile(java.io.File f)
          Loads an image from a file.
static java.awt.image.BufferedImage loadGIF(java.io.File f)
          Load a GIF format image using the BYTE_TYPE_INDEXED format (fastest)
static java.awt.image.BufferedImage loadGIF(java.io.File f, int buffertype)
          Load a GIF format image.
static java.awt.image.BufferedImage loadGIF(java.io.InputStream is)
          Load a GIF format image using the BYTE_TYPE_INDEXED format (fastest)
static java.awt.image.BufferedImage loadGIF(java.io.InputStream is, int buffertype)
          Load a GIF format image.
static java.awt.image.BufferedImage loadJPEG(java.io.File f)
          Loads a JPEG image from a file.
static java.awt.image.BufferedImage loadJPEG(java.io.InputStream is)
          Loads a JPEG image from a stream.
static java.awt.image.BufferedImage loadPNG(java.io.InputStream is)
           
static java.awt.image.BufferedImage loadStream(java.io.InputStream is, java.lang.String type)
          Loads an image from a stream.
static void main(java.lang.String[] args)
           
static java.awt.image.BufferedImage makeBuffered(java.awt.Image i)
          Converts an Image into a same-size buffered image if it's not already a BufferedImage.
static java.awt.image.BufferedImage makeBuffered(java.awt.Image i, int bit)
          Converts an Image into a same-size buffered image if it's not already a BufferedImage.
static java.awt.image.BufferedImage resizeFiltered_RAW(java.awt.image.BufferedImage i, int w, int h)
           
static java.awt.image.BufferedImage resizeFiltered_RAW(java.awt.image.BufferedImage bi, int w, int h, ResamplerFilter fil)
           
static java.awt.image.BufferedImage resizeFiltered(java.awt.image.BufferedImage i, int w, int h)
          Resizes a BufferedImage while keeping it's aspect ratio, using the optimal filtered stuff...
static java.awt.image.BufferedImage resizeFiltered(java.awt.image.BufferedImage bi, int w, int h, ResamplerFilter fil)
          Resizes a BufferedImage while keeping it's aspect ratio, using the optimal filtered stuff...
static java.awt.Dimension resizeWithAspect(java.awt.Dimension dest, java.awt.Dimension src)
           
static java.awt.Dimension resizeWithAspect(int dw, int dh, int sw, int sh)
          Does a resize of an object with size (sw, sh) to fit within a rectangle of (dw, dh) while keeping the same aspect ratio
static void saveGIF(java.awt.image.BufferedImage bi, java.io.File f)
          Saves an image as a GIF file to a stream.
static void saveGIF(java.awt.image.BufferedImage bi, java.io.OutputStream os)
          Saves an image as a GIF file to a stream.
static void saveImageByMime(java.io.OutputStream os, java.awt.image.BufferedImage bi, java.lang.String mime)
           
static void saveJPEG(java.awt.image.BufferedImage bi, java.io.File f, double qf)
          Saves an image as a JPEG to the stream specified, with the quality spec'd.
static void saveJPEG(java.awt.image.BufferedImage bi, java.io.OutputStream os, double qf)
          Saves an image as a JPEG to the stream specified, with the quality spec'd.
static void savePNG(java.awt.image.BufferedImage bi, java.io.File f)
           
static void savePNG(java.awt.image.BufferedImage bi, java.io.OutputStream f)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resizeWithAspect

public static java.awt.Dimension resizeWithAspect(int dw,
                                                  int dh,
                                                  int sw,
                                                  int sh)
Does a resize of an object with size (sw, sh) to fit within a rectangle of (dw, dh) while keeping the same aspect ratio


resizeWithAspect

public static java.awt.Dimension resizeWithAspect(java.awt.Dimension dest,
                                                  java.awt.Dimension src)

makeBuffered

public static java.awt.image.BufferedImage makeBuffered(java.awt.Image i,
                                                        int bit)
Converts an Image into a same-size buffered image if it's not already a BufferedImage.


makeBuffered

public static java.awt.image.BufferedImage makeBuffered(java.awt.Image i)
Converts an Image into a same-size buffered image if it's not already a BufferedImage.


loadPNG

public static java.awt.image.BufferedImage loadPNG(java.io.InputStream is)
                                            throws java.io.IOException
Throws:
java.io.IOException

loadJPEG

public static java.awt.image.BufferedImage loadJPEG(java.io.InputStream is)
                                             throws java.io.IOException
Loads a JPEG image from a stream. The image is returned as a BufferedImage.

Throws:
java.io.IOException

loadJPEG

public static java.awt.image.BufferedImage loadJPEG(java.io.File f)
                                             throws java.io.IOException
Loads a JPEG image from a file. The image is returned as a BufferedImage.

Throws:
java.io.IOException

saveJPEG

public static void saveJPEG(java.awt.image.BufferedImage bi,
                            java.io.OutputStream os,
                            double qf)
                     throws java.io.IOException
Saves an image as a JPEG to the stream specified, with the quality spec'd. If q is zero the default quality will be used.

Throws:
java.io.IOException

saveJPEG

public static void saveJPEG(java.awt.image.BufferedImage bi,
                            java.io.File f,
                            double qf)
                     throws java.io.IOException
Saves an image as a JPEG to the stream specified, with the quality spec'd. If q is zero the default quality will be used.

Throws:
java.io.IOException

loadGIF

public static java.awt.image.BufferedImage loadGIF(java.io.File f,
                                                   int buffertype)
                                            throws java.io.IOException
Load a GIF format image.

Throws:
java.io.IOException

loadGIF

public static java.awt.image.BufferedImage loadGIF(java.io.InputStream is,
                                                   int buffertype)
                                            throws java.io.IOException
Load a GIF format image.

Throws:
java.io.IOException

loadGIF

public static java.awt.image.BufferedImage loadGIF(java.io.InputStream is)
                                            throws java.io.IOException
Load a GIF format image using the BYTE_TYPE_INDEXED format (fastest)

Throws:
java.io.IOException

loadGIF

public static java.awt.image.BufferedImage loadGIF(java.io.File f)
                                            throws java.io.IOException
Load a GIF format image using the BYTE_TYPE_INDEXED format (fastest)

Throws:
java.io.IOException

saveGIF

public static void saveGIF(java.awt.image.BufferedImage bi,
                           java.io.OutputStream os)
                    throws java.lang.Exception
Saves an image as a GIF file to a stream.

Throws:
java.lang.Exception

saveGIF

public static void saveGIF(java.awt.image.BufferedImage bi,
                           java.io.File f)
                    throws java.lang.Exception
Saves an image as a GIF file to a stream.

Throws:
java.lang.Exception

savePNG

public static void savePNG(java.awt.image.BufferedImage bi,
                           java.io.File f)
                    throws java.lang.Exception
Throws:
java.lang.Exception

savePNG

public static void savePNG(java.awt.image.BufferedImage bi,
                           java.io.OutputStream f)
                    throws java.lang.Exception
Throws:
java.lang.Exception

loadFile

public static java.awt.image.BufferedImage loadFile(java.io.File f)
                                             throws java.io.IOException
Loads an image from a file. If the extension of the file is known (either gif, jpg or jpeg) then the file is loaded using one of the optimized loaders; if not the routine returns null.

Throws:
java.io.IOException

loadFile_image

public static java.awt.Image loadFile_image(java.io.File f)
                                     throws java.io.IOException
Loads an image from a file. If the extension of the file is known (either gif, jpg or jpeg) then the file is loaded using one of the optimized loaders; if not the routine returns null.

Throws:
java.io.IOException

loadStream

public static java.awt.image.BufferedImage loadStream(java.io.InputStream is,
                                                      java.lang.String type)
                                               throws java.io.IOException
Loads an image from a stream. The image type must contain jpg or jpeg for a JPEG file, or gif for a GIF file.

Throws:
java.io.IOException

awtLoadImage

public static java.awt.Image awtLoadImage(java.io.File f)
                                   throws java.io.IOException
Loads the image from the file into an image. This loads exactly according to the AWT, without using any of the extensions. It will return a completely loaded image however.

Throws:
java.io.IOException

awtLoadBufferedImage

public static java.awt.image.BufferedImage awtLoadBufferedImage(java.io.File f)
                                                         throws java.io.IOException
Loads the image from the file into an image. This loads exactly according to the AWT, without using any of the extensions. After the load the image is copied into a BufferedImage and returned. This is VERY expensive so try to use another function instead!

Throws:
java.io.IOException

resizeFiltered_RAW

public static java.awt.image.BufferedImage resizeFiltered_RAW(java.awt.image.BufferedImage bi,
                                                              int w,
                                                              int h,
                                                              ResamplerFilter fil)

resizeFiltered_RAW

public static java.awt.image.BufferedImage resizeFiltered_RAW(java.awt.image.BufferedImage i,
                                                              int w,
                                                              int h)

resizeFiltered

public static java.awt.image.BufferedImage resizeFiltered(java.awt.image.BufferedImage bi,
                                                          int w,
                                                          int h,
                                                          ResamplerFilter fil)
Resizes a BufferedImage while keeping it's aspect ratio, using the optimal filtered stuff... This uses the default filter..


resizeFiltered

public static java.awt.image.BufferedImage resizeFiltered(java.awt.image.BufferedImage i,
                                                          int w,
                                                          int h)
Resizes a BufferedImage while keeping it's aspect ratio, using the optimal filtered stuff... This uses the default filter..


awtResize

public static java.awt.image.BufferedImage awtResize(java.awt.image.BufferedImage bi,
                                                     int w,
                                                     int h)
Resizes a BufferedImage while keeping it's aspect ratio, using the AWT mechanism... This returns a lower quality image; use resizeFiltered to get a filtered resampled image.


findQualityBySize

public static double findQualityBySize(java.awt.image.BufferedImage bi,
                                       int sizenear)
Taking a BufferedImage, this function will try to find a JPEG quality factor that will save the image with a size around the size specified. This is done by looping a number of times and adjusting the quality until something reasonable is obtained.


saveImageByMime

public static void saveImageByMime(java.io.OutputStream os,
                                   java.awt.image.BufferedImage bi,
                                   java.lang.String mime)
                            throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)