EchoPoint
1.0

echopoint.image
Class ImageKit

java.lang.Object
  extended byechopoint.image.ImageKit

public class ImageKit
extends java.lang.Object

A utility to class to help with ImageReference manipulation

Author:
Brad Baker

Field Summary
static java.awt.MediaTracker imageMediaTracker
          You can use this object as an valid MediaTracker
static java.awt.Component imageObserver
          You can use this object as an valid ImageObserver
 
Method Summary
static java.awt.image.BufferedImage copyImage(java.awt.Image srcImage)
          This method will return copy a source Image and return a new BufferedImage.
static nextapp.echo.ImageReference createImageRef(nextapp.echo.Color background, int width, int height)
          Creates an ImageReference that is width * height in dimensions and has the specified background color.
static java.awt.Image enlargeImageSpliceHoriz(java.awt.Image srcImage, int y, int newH)
          Called to enlarge an image by splicing it horizontally (along the Y axis) at y and filling the new section with a 1 pixel sample at y This method will only enlarge the image.
static java.awt.Image enlargeImageSpliceVert(java.awt.Image srcImage, int x, int newW)
          Called to enlarge an image by splicing it vertically (along the X axis) at x and filling the new section with a 1 pixel sample at x This method will only enlarge the image.
static java.awt.Image flipImage(java.awt.Image srcImage)
          This method flips the source image through the horizontal plane, eg. the top become the bottom.
static nextapp.echo.ImageReference getColoredImageRef(nextapp.echo.Color backgroundColor, int width, int height)
          Returns an ImageReference that is width * height in dimensions with the specified background color.
static java.awt.image.ColorModel getColorModel(java.awt.Image srcImage)
          This method will return the ColorModel of an Image.
static nextapp.echo.ImageReference getTransparentImageRef(int width, int height)
          Returns an transparent ImageReference that is width * height in dimensions
static boolean hasAlphaChannel(java.awt.Image srcImage)
          This method returns true if the provided Image has an alpha channel
static java.awt.Image loadCachedImage(java.lang.String imageFileName)
          Loads an image file from disk and returns an java.awt.Image, which is then cached.
static java.awt.Image loadCachedImage(java.lang.String imageFileName, int width, int height)
          Loads an image file from disk and returns an java.awt.Image, which is then cached.
static java.awt.Image loadCachedImage(java.net.URL imageUrl)
          Loads an image file from disk and returns an java.awt.Image, which is then cached.
static java.awt.Image loadCachedImage(java.net.URL imageUrl, int width, int height)
          Loads an image file from disk and returns an java.awt.Image, which is then cached.
static java.awt.Image loadCachedResourceImage(java.lang.String imageResourceName)
          Loads an image file from a named Java resource and returns an java.awt.Image which is then cached.
static java.awt.Image loadCachedResourceImage(java.lang.String imageResourceName, int width, int height)
          Loads an image file from a named Java resource and returns an java.awt.Image which is then cached.
static java.awt.Image loadImage(java.lang.String imageFileName)
          Loads an image file from disk and returns an java.awt.Image.
static java.awt.Image loadImage(java.lang.String imageFileName, int width, int height)
          Loads an image file from disk and returns an java.awt.Image.
static java.awt.Image loadImage(java.net.URL imageUrl)
          Loads an image file from disk and returns an java.awt.Image.
static java.awt.Image loadImage(java.net.URL imageUrl, int width, int height)
          Loads an image file from disk and returns an java.awt.Image.
static java.awt.Image loadResourceImage(java.lang.String imageResourceName)
          Loads an image file from a named Java resource and returns an java.awt.Image.
static java.awt.Image loadResourceImage(java.lang.String imageResourceName, int width, int height)
          Loads an image file from a named Java resource and returns an java.awt.Image.
static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage)
          Returns a BufferedImage, that is same as the original java.awt.Image.
static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage, int width, int height)
          Returns a BufferedImage, that is same as the original java.awt.Image.
static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage, int width, int height, int imageType)
          Returns a BufferedImage, that is same as the original java.awt.Image, scaled to width and height.
static java.awt.Image makeImageColorTransparent(java.awt.Image srcImage, nextapp.echo.Color markerColor)
          This will change the image so that any occurence of the specified color is fully transparent, ie has an alpha value of 0.
static java.awt.Image makeImageColorTransparent(java.awt.Image srcImage, nextapp.echo.Color markerColor, int alpha)
          This will change the image so that any occurence of the specified color is changed to have an alpha value of 'alpha'; This method works inline on the provided image.
static java.awt.image.BufferedImage makeImageGreyScale(java.awt.Image srcImage)
           
static java.awt.Image mirrowImage(java.awt.Image srcImage)
          This method mirrows the source image through the vertical plane, eg. the left become the right.
static java.text.AttributedString readSerializedAttributedString(java.io.ObjectInputStream in)
          Reads in a serialized AttributeString and restores all Serializable objects contained within it.
static java.awt.Image readSerializedImage(java.io.ObjectInputStream in)
          Reads an image in from a serilisation stream.
static java.awt.Image rotateImage(java.awt.Image srcImage)
          This method roteates the source image through the horizontal and vertical plane.
static java.awt.Image swapImageColors(java.awt.Image srcImage, nextapp.echo.Color srcColor, nextapp.echo.Color destColor)
          This will change all occurences of srcColor to destColor in the image.
static boolean waitForImage(java.awt.Image srcImage)
          Waits for an Image to be loaded by using a MediaTracker internally.
static void writeSerializedAttributedString(java.io.ObjectOutputStream out, java.text.AttributedString as)
          Writes an AttributedString to an object output stream and saves all Serializable obejcts contained within it.
static void writeSerializedImage(java.io.ObjectOutputStream out, java.awt.Image srcImage)
          Writes an Image out to a serialisation stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageObserver

public static final java.awt.Component imageObserver
You can use this object as an valid ImageObserver


imageMediaTracker

public static final java.awt.MediaTracker imageMediaTracker
You can use this object as an valid MediaTracker

Method Detail

createImageRef

public static nextapp.echo.ImageReference createImageRef(nextapp.echo.Color background,
                                                         int width,
                                                         int height)
Creates an ImageReference that is width * height in dimensions and has the specified background color.


getTransparentImageRef

public static nextapp.echo.ImageReference getTransparentImageRef(int width,
                                                                 int height)
Returns an transparent ImageReference that is width * height in dimensions


getColoredImageRef

public static nextapp.echo.ImageReference getColoredImageRef(nextapp.echo.Color backgroundColor,
                                                             int width,
                                                             int height)
Returns an ImageReference that is width * height in dimensions with the specified background color. The returned ImageReference is cached for fast retrieval but it uses SoftReferences so it will degrade in low memory conditions.


copyImage

public static java.awt.image.BufferedImage copyImage(java.awt.Image srcImage)
This method will return copy a source Image and return a new BufferedImage.

This differs from makeBufferedImage() in that it gauruntees to make a new copy of the image data whereas makeBufferedImage() will return the same object if its already a BufferedImage.

Parameters:
srcImage - the source Image
Returns:
- a completely new BufferedImage

loadImage

public static java.awt.Image loadImage(java.lang.String imageFileName)
Loads an image file from disk and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache.

Parameters:
imageFileName - - the image file to be loaded
Returns:
Image - the loaded AWT image

loadCachedImage

public static java.awt.Image loadCachedImage(java.lang.String imageFileName)
Loads an image file from disk and returns an java.awt.Image, which is then cached. The image is guaranteed to be fully loaded when this method returns. Soft references are used so that the image cache can be reclaimed in low memory conditions.

Parameters:
imageFileName - - the image file to be loaded
Returns:
Image - the loaded AWT image

loadImage

public static java.awt.Image loadImage(java.lang.String imageFileName,
                                       int width,
                                       int height)
Loads an image file from disk and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache. The image will be scaled to the specified width and height.

Parameters:
imageFileName - - the image file to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

loadCachedImage

public static java.awt.Image loadCachedImage(java.lang.String imageFileName,
                                             int width,
                                             int height)
Loads an image file from disk and returns an java.awt.Image, which is then cached. The image is guaranteed to be fully loaded when this method returns. Soft references are used so that the image cache can be reclaimed in low memory conditions. The image will be scaled to the specified width and height.

Parameters:
imageFileName - - the image file to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

loadImage

public static java.awt.Image loadImage(java.net.URL imageUrl)
Loads an image file from disk and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache.

Parameters:
imageUrl - - the image URL to be loaded
Returns:
Image - the loaded AWT image

loadCachedImage

public static java.awt.Image loadCachedImage(java.net.URL imageUrl)
Loads an image file from disk and returns an java.awt.Image, which is then cached. The image is guaranteed to be fully loaded when this method returns. Soft references are used so that the image cache can be reclaimed in low memory conditions.

Parameters:
imageUrl - - the image URL to be loaded
Returns:
Image - the loaded AWT image

loadImage

public static java.awt.Image loadImage(java.net.URL imageUrl,
                                       int width,
                                       int height)
Loads an image file from disk and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache. The image will be scaled to the specified width and height.

Parameters:
imageUrl - - the image URL to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

loadCachedImage

public static java.awt.Image loadCachedImage(java.net.URL imageUrl,
                                             int width,
                                             int height)
Loads an image file from disk and returns an java.awt.Image, which is then cached. The image is guaranteed to be fully loaded when this method returns. Soft references are used so that the image cache can be reclaimed in low memory conditions. The image will be scaled to the specified width and height.

Parameters:
imageUrl - - the image URL to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

loadResourceImage

public static java.awt.Image loadResourceImage(java.lang.String imageResourceName)
Loads an image file from a named Java resource and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache.

Parameters:
imageResourceName - - the image resource to be loaded
Returns:
Image - the loaded AWT image

loadCachedResourceImage

public static java.awt.Image loadCachedResourceImage(java.lang.String imageResourceName)
Loads an image file from a named Java resource and returns an java.awt.Image which is then cached. The image is guaranteed to be fully loaded when this method returns. Soft references are used so that the image cache can be reclaimed in low memory conditions.

Parameters:
imageResourceName - - the image resource to be loaded
Returns:
Image - the loaded AWT image

loadResourceImage

public static java.awt.Image loadResourceImage(java.lang.String imageResourceName,
                                               int width,
                                               int height)
Loads an image file from a named Java resource and returns an java.awt.Image. The image is guaranteed to be fully loaded when this method returns and is not contained in any internal cache. The image will be scaled to the specified width and height.

Parameters:
imageResourceName - - the image resource to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

loadCachedResourceImage

public static java.awt.Image loadCachedResourceImage(java.lang.String imageResourceName,
                                                     int width,
                                                     int height)
Loads an image file from a named Java resource and returns an java.awt.Image which is then cached. The image is guaranteed to be fully loaded when this method returns The image will be scaled to the specified width and height.

Parameters:
imageResourceName - - the image resource to be loaded
width - - the width of the new image
height - - the height of the new image
Returns:
Image - the loaded AWT image

makeBufferedImage

public static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage)
Returns a BufferedImage, that is same as the original java.awt.Image. Its smart about passing in BufferedImage objects and will simply return them unchanged.

The image type will be BufferedImage.TYPE_INT_ARGB if it has an alpha channel other wise it will be BufferedImage.TYPE_INT_RGB

Parameters:
srcImage - Image - the image to be converted
Returns:
a BufferedImage

makeBufferedImage

public static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage,
                                                             int width,
                                                             int height)
Returns a BufferedImage, that is same as the original java.awt.Image. Its smart about passing in BufferedImage objects and will simply return them unchanged.

The image type will be BufferedImage.TYPE_INT_ARGB if it has an alpha channel other wise it will be BufferedImage.TYPE_INT_RGB type will be BufferedImage.TYPE_INT_ARGB.

The image will be scaled to the width/height dimensions.

Parameters:
srcImage - - the image to be converted
width - - the width of the new image
height - - the height of the new image
Returns:
a BufferedImage

makeBufferedImage

public static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image srcImage,
                                                             int width,
                                                             int height,
                                                             int imageType)
Returns a BufferedImage, that is same as the original java.awt.Image, scaled to width and height. Its smart about passing in BufferedImage objects and will simply return them unchanged.

Parameters:
srcImage - - the image to be converted
width - - the width of the new image
height - - the height of the new image
imageType - - can be on of BufferedImage types such as BufferedImage.TYPE_INT_ARGB
Returns:
a BufferedImage

getColorModel

public static java.awt.image.ColorModel getColorModel(java.awt.Image srcImage)
This method will return the ColorModel of an Image.

Parameters:
srcImage - the source Image
Returns:
- the ColorModel of the image

hasAlphaChannel

public static boolean hasAlphaChannel(java.awt.Image srcImage)
This method returns true if the provided Image has an alpha channel

Parameters:
srcImage - - the image to check for an alpha channel
Returns:
true if the provided Image has an alpha channel

swapImageColors

public static java.awt.Image swapImageColors(java.awt.Image srcImage,
                                             nextapp.echo.Color srcColor,
                                             nextapp.echo.Color destColor)
This will change all occurences of srcColor to destColor in the image. Any alpha valuews in the image will be left intact.

This method works inline on the provided image. It does NOT make a copy of the source image.

Parameters:
srcImage - - the image to be transformed
srcColor - - the source color
destColor - - the dest color
Returns:
- a same image with the source and dest colors swapped.

makeImageColorTransparent

public static java.awt.Image makeImageColorTransparent(java.awt.Image srcImage,
                                                       nextapp.echo.Color markerColor)
This will change the image so that any occurence of the specified color is fully transparent, ie has an alpha value of 0.

This method works inline on the provided image. It does NOT make a copy of the source image.

Parameters:
srcImage - - the image to be transformed
markerColor - - the color to be made transparent
Returns:
- a new image with the specified color as fully transparent

makeImageColorTransparent

public static java.awt.Image makeImageColorTransparent(java.awt.Image srcImage,
                                                       nextapp.echo.Color markerColor,
                                                       int alpha)
This will change the image so that any occurence of the specified color is changed to have an alpha value of 'alpha';

This method works inline on the provided image. It does NOT make a copy of the source image.

Parameters:
srcImage - - the image to be transformed
markerColor - - the color to be made transparent
alpha - - an alpha value between 0 and 255
Returns:
- a same image with the specified color as having the alpha value

makeImageGreyScale

public static java.awt.image.BufferedImage makeImageGreyScale(java.awt.Image srcImage)

readSerializedAttributedString

public static java.text.AttributedString readSerializedAttributedString(java.io.ObjectInputStream in)
                                                                 throws java.io.IOException,
                                                                        java.lang.ClassNotFoundException
Reads in a serialized AttributeString and restores all Serializable objects contained within it.

Parameters:
in -
Returns:
AttributedString - the new AttributedString
Throws:
java.io.IOException
java.lang.ClassNotFoundException

readSerializedImage

public static java.awt.Image readSerializedImage(java.io.ObjectInputStream in)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Reads an image in from a serilisation stream. It must have been written with the writeSerializedImage method. Most of the code was taken from the Echo AwtImageReference, so kudos to NextApp.

Parameters:
in -
Returns:
Image
Throws:
java.io.IOException
java.lang.ClassNotFoundException

waitForImage

public static boolean waitForImage(java.awt.Image srcImage)
Waits for an Image to be loaded by using a MediaTracker internally.

Parameters:
srcImage - - the source Image
Returns:
false if the image cannot be loaded or true if it is down.

writeSerializedAttributedString

public static void writeSerializedAttributedString(java.io.ObjectOutputStream out,
                                                   java.text.AttributedString as)
                                            throws java.io.IOException
Writes an AttributedString to an object output stream and saves all Serializable obejcts contained within it.

Parameters:
out -
as -
Throws:
java.io.IOException

writeSerializedImage

public static void writeSerializedImage(java.io.ObjectOutputStream out,
                                        java.awt.Image srcImage)
                                 throws java.io.IOException
Writes an Image out to a serialisation stream. Most of the code was taken from the Echo AwtImageReference, so kudos to NextApp.

Parameters:
out - the object output stream
srcImage - - the source Image
Throws:
java.io.IOException - if need be

mirrowImage

public static java.awt.Image mirrowImage(java.awt.Image srcImage)
This method mirrows the source image through the vertical plane, eg. the left become the right. This will work inline on the image if its a BufferedImage and will create a copy if its not.

Parameters:
srcImage - the source Image
Returns:
the image mirrowed

flipImage

public static java.awt.Image flipImage(java.awt.Image srcImage)
This method flips the source image through the horizontal plane, eg. the top become the bottom. This will work inline on the image if its a BufferedImage and will create a copy if its not.

Parameters:
srcImage - the source Image
Returns:
the image flipped

rotateImage

public static java.awt.Image rotateImage(java.awt.Image srcImage)
This method roteates the source image through the horizontal and vertical plane. This is the equivalent of rotating it through 180 degrees. This will work inline on the image if its a BufferedImage and will create a copy if its not.

Parameters:
srcImage - the source Image
Returns:
the image rotated 180 degrees.

enlargeImageSpliceVert

public static java.awt.Image enlargeImageSpliceVert(java.awt.Image srcImage,
                                                    int x,
                                                    int newW)
Called to enlarge an image by splicing it vertically (along the X axis) at x and filling the new section with a 1 pixel sample at x

This method will only enlarge the image. If the new width is less than or equal to the current width, then the srcImage is returned.

Parameters:
srcImage - - the source Image
x - - the position to splice at
newW - - the new width of the image
Returns:
an image that is enlarged to the new width via splicing

enlargeImageSpliceHoriz

public static java.awt.Image enlargeImageSpliceHoriz(java.awt.Image srcImage,
                                                     int y,
                                                     int newH)
Called to enlarge an image by splicing it horizontally (along the Y axis) at y and filling the new section with a 1 pixel sample at y

This method will only enlarge the image. If the new height is less than or equal to the current height, then the srcImage is returned.

Parameters:
srcImage - - the source Image
y - - the position to splice at
newH - - the new height of the image
Returns:
an image that is enlarged to the new height via splicing

EchoPoint
1.0