j2d
Class ImageSaveUtils

java.lang.Object
  extended by j2d.ImageSaveUtils

public class ImageSaveUtils
extends java.lang.Object


Nested Class Summary
static class ImageSaveUtils.ImageUtilException
           
 
Field Summary
static java.lang.String BMP
           
static float[] CIRCLE_3
           
static int EDGES_FREICHEN
           
static int EDGES_PREWITT
           
static int EDGES_ROBERTS
           
static int EDGES_SOBEL
           
static java.util.Map<java.lang.String,java.lang.String> fileStoreOpts
           
static java.lang.String FPX
           
static float[] FREICHEN_H
           
static float[] FREICHEN_V
           
static java.lang.String GIF
           
static java.lang.String JPEG
           
static java.lang.String JPG
           
static java.lang.String PNG
           
static java.lang.String PNM
           
static float[] PREWITT_H
           
static float[] PREWITT_V
           
static float[] RECTANGLE_3x9
           
static float[] RECTANGLE_9x3
           
static float[] ROBERTS_H
           
static float[] ROBERTS_V
           
static float[] SOBEL_H
           
static float[] SOBEL_V
           
static float[] SQUARE_3
           
static java.lang.String[] supportedFormats
           
static java.lang.String TIF
           
static java.lang.String TIFF
           
 
Constructor Summary
ImageSaveUtils()
           
 
Method Summary
static javax.media.jai.PlanarImage close(javax.media.jai.PlanarImage image, float[] data, int width, int height)
           
static javax.media.jai.PlanarImage detectEdges(javax.media.jai.PlanarImage image, int method)
           
static javax.media.jai.PlanarImage detectFCEdges(javax.media.jai.PlanarImage image)
          Applies a Frei-Chen edge detection algorithm.
static javax.media.jai.PlanarImage dilate(javax.media.jai.PlanarImage image, float[] data, int width, int height)
           
static javax.media.jai.PlanarImage drawLine(javax.media.jai.PlanarImage image, int startx, int starty, int width, int height)
           
static javax.media.jai.PlanarImage erode(javax.media.jai.PlanarImage image, float[] data, int width, int height)
           
static javax.media.jai.PlanarImage grayscale(javax.media.jai.PlanarImage image)
          Converts an image to a grayscale image.
static javax.media.jai.PlanarImage loadImage(java.io.File file)
          Attempts to load an image from the specified file.
static javax.media.jai.PlanarImage loadImage(java.io.InputStream is)
          Attempts to load an image from the provided InputStream.
static javax.media.jai.PlanarImage newImage(javax.media.jai.PlanarImage src, int width, int height, boolean black)
           
static javax.media.jai.PlanarImage open(javax.media.jai.PlanarImage image, float[] data, int width, int height)
           
static javax.media.jai.PlanarImage pureBW(javax.media.jai.PlanarImage source)
           
static void saveImage(javax.media.jai.PlanarImage image, java.io.OutputStream os)
          Writes the provided image to an output stream as a JPEG image.
static void saveImage(javax.media.jai.PlanarImage image, java.io.OutputStream os, java.lang.String format)
          Writes the provided image to an output stream.
static java.lang.String saveImage(java.lang.String name, java.io.File dir, javax.media.jai.PlanarImage image, java.lang.String format)
          Saves the provided image.
static javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage image, float factor, javax.media.jai.Interpolation interp)
          Scales an image by the specified factor optionally using the provided interpolation algorithm.
static javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage image, int maxX, int maxY, boolean enlarge, javax.media.jai.Interpolation interp)
          Scales the provided image to fit within the maximum x, y coordinates specified.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIF

public static final java.lang.String TIF
See Also:
Constant Field Values

TIFF

public static final java.lang.String TIFF
See Also:
Constant Field Values

BMP

public static final java.lang.String BMP
See Also:
Constant Field Values

FPX

public static final java.lang.String FPX
See Also:
Constant Field Values

GIF

public static final java.lang.String GIF
See Also:
Constant Field Values

JPEG

public static final java.lang.String JPEG
See Also:
Constant Field Values

JPG

public static final java.lang.String JPG
See Also:
Constant Field Values

PNG

public static final java.lang.String PNG
See Also:
Constant Field Values

PNM

public static final java.lang.String PNM
See Also:
Constant Field Values

supportedFormats

public static final java.lang.String[] supportedFormats

fileStoreOpts

public static final java.util.Map<java.lang.String,java.lang.String> fileStoreOpts

EDGES_SOBEL

public static final int EDGES_SOBEL
See Also:
Constant Field Values

EDGES_ROBERTS

public static final int EDGES_ROBERTS
See Also:
Constant Field Values

EDGES_PREWITT

public static final int EDGES_PREWITT
See Also:
Constant Field Values

EDGES_FREICHEN

public static final int EDGES_FREICHEN
See Also:
Constant Field Values

SOBEL_H

public static final float[] SOBEL_H

SOBEL_V

public static final float[] SOBEL_V

ROBERTS_H

public static final float[] ROBERTS_H

ROBERTS_V

public static final float[] ROBERTS_V

PREWITT_H

public static final float[] PREWITT_H

PREWITT_V

public static final float[] PREWITT_V

FREICHEN_H

public static final float[] FREICHEN_H

FREICHEN_V

public static final float[] FREICHEN_V

SQUARE_3

public static final float[] SQUARE_3

CIRCLE_3

public static final float[] CIRCLE_3

RECTANGLE_9x3

public static final float[] RECTANGLE_9x3

RECTANGLE_3x9

public static final float[] RECTANGLE_3x9
Constructor Detail

ImageSaveUtils

public ImageSaveUtils()
Method Detail

loadImage

public static javax.media.jai.PlanarImage loadImage(java.io.File file)
Attempts to load an image from the specified file. If the image cannot be loaded, this will return null. Note that this supresses (and logs) any possible FileNotFoundException or IOException.

Parameters:
file - An File containing the image data.
Returns:
a PlanarImage object containing the image data from the provided File or null if the image could not be loaded.

loadImage

public static javax.media.jai.PlanarImage loadImage(java.io.InputStream is)
Attempts to load an image from the provided InputStream. If the image cannot be loaded, this will return null. Note that this supresses (and logs) any possible IOException.

Parameters:
is - An InputStream containing the image data.
Returns:
a PlanarImage object containing the image data from the provided InputStream or null if the image could not be loaded.

saveImage

public static java.lang.String saveImage(java.lang.String name,
                                         java.io.File dir,
                                         javax.media.jai.PlanarImage image,
                                         java.lang.String format)
                                  throws ImageSaveUtils.ImageUtilException
Saves the provided image.

Parameters:
name - The name of the image (without the file extension).
dir - The directory in which the image is to be saved.
image - The image to be saved.
format - The format in which the image is to be saved. This must be one of the formats specified by ImageUtils.supportedFormats.
Returns:
The name of the saved file (with the extension).
Throws:
ImageSaveUtils.ImageUtilException

saveImage

public static void saveImage(javax.media.jai.PlanarImage image,
                             java.io.OutputStream os,
                             java.lang.String format)
                      throws ImageSaveUtils.ImageUtilException
Writes the provided image to an output stream.

Parameters:
image - The image to be written.
os - The output stream to which the image will be written.
format - The format in which the image is to be saved. This must a format specified by ImageUtils.supportedFormats.
Throws:
ImageSaveUtils.ImageUtilException

saveImage

public static void saveImage(javax.media.jai.PlanarImage image,
                             java.io.OutputStream os)
                      throws ImageSaveUtils.ImageUtilException
Writes the provided image to an output stream as a JPEG image.

Parameters:
image - The image to be written.
os - The output stream to which the image will be written.
Throws:
ImageSaveUtils.ImageUtilException

scaleImage

public static javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage image,
                                                     float factor,
                                                     javax.media.jai.Interpolation interp)
Scales an image by the specified factor optionally using the provided interpolation algorithm. If the interpolation algorithm is null, a bicubic interpolation will be used.

Parameters:
image - The image to be scaled.
factor - The factor by which to scale the image.
interp - (optional) The interpolation algorithm to be used. If this is null, a default interpolation algorithm will be applied.
Returns:
The scaled image.

scaleImage

public static javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage image,
                                                     int maxX,
                                                     int maxY,
                                                     boolean enlarge,
                                                     javax.media.jai.Interpolation interp)
Scales the provided image to fit within the maximum x, y coordinates specified.

Parameters:
image - The image to be scaled.
maxX - The maximum number of pixels in the x direction.
maxY - The maximum number of pixels in the y direction.
enlarge - flag indicating whether to increase the image size if it is already smaller than the the provided x, y coordinates.
interp - (optional) The interpolation algorithm to be used. If this is null, a default interpolation algorithm will be applied.
Returns:
The scaled image.

grayscale

public static javax.media.jai.PlanarImage grayscale(javax.media.jai.PlanarImage image)
Converts an image to a grayscale image.

Parameters:
image - The image to be converted.
Returns:
The grayscale version of the image.

detectFCEdges

public static javax.media.jai.PlanarImage detectFCEdges(javax.media.jai.PlanarImage image)
Applies a Frei-Chen edge detection algorithm.

Parameters:
image - The image to convert.
Returns:
The resulting image.

detectEdges

public static javax.media.jai.PlanarImage detectEdges(javax.media.jai.PlanarImage image,
                                                      int method)

dilate

public static javax.media.jai.PlanarImage dilate(javax.media.jai.PlanarImage image,
                                                 float[] data,
                                                 int width,
                                                 int height)

erode

public static javax.media.jai.PlanarImage erode(javax.media.jai.PlanarImage image,
                                                float[] data,
                                                int width,
                                                int height)

open

public static javax.media.jai.PlanarImage open(javax.media.jai.PlanarImage image,
                                               float[] data,
                                               int width,
                                               int height)

close

public static javax.media.jai.PlanarImage close(javax.media.jai.PlanarImage image,
                                                float[] data,
                                                int width,
                                                int height)

drawLine

public static javax.media.jai.PlanarImage drawLine(javax.media.jai.PlanarImage image,
                                                   int startx,
                                                   int starty,
                                                   int width,
                                                   int height)

pureBW

public static javax.media.jai.PlanarImage pureBW(javax.media.jai.PlanarImage source)

newImage

public static javax.media.jai.PlanarImage newImage(javax.media.jai.PlanarImage src,
                                                   int width,
                                                   int height,
                                                   boolean black)