com.tensegrity.graphics.awt
Class AWTImageOperations

java.lang.Object
  extended bycom.tensegrity.graphics.awt.AWTImageOperations
All Implemented Interfaces:
ImageOperations

public class AWTImageOperations
extends java.lang.Object
implements ImageOperations

The AWTImageOperations class provides some basic functionalities used when working with the sun swing toolkit.

Version:
$Id: AWTImageOperations.java,v 1.6 2005/10/11 15:06:29 BurkhardWick Exp $
Author:
MichaelKegel

Constructor Summary
AWTImageOperations()
          Private constructor to avoid instantiation.
 
Method Summary
static boolean canWriteFormat(java.lang.String formatName)
          Returns true if the specified format name can be written
 Raster convertImageToRaster(java.awt.Image image)
          Converts the Image given by image to a Raster object.
 byte[] jpegEncode(int width, int height, int[] pixels, float quality, boolean forceBaseline)
          Encodes the given pixel data to JPEG data.
 java.awt.Image loadAWTImage(java.lang.String imagepath)
           
 java.awt.Image loadAWTImage(java.net.URL imagepath)
           
 java.awt.Image loadAWTImageResource(java.lang.Class refClass, java.lang.String imagepath)
           
 java.awt.Image loadAWTImageResource(java.lang.String imagepath)
           
 Raster loadImage(java.lang.String imagepath)
          Loads the image from the source given by imagepath.
 Raster loadImage(java.net.URL imagepath)
           
 Raster loadImageResource(java.lang.Class referenceclass, java.lang.String imagepath)
           
 Raster loadImageResource(java.lang.String imagepath)
          Loads the image from the source given by imagepath.
 void registerReferenceClass(java.lang.Class refClass)
          Registers the reference class that is used when loading images.
 void registerReferenceComponent(java.awt.Component component)
          Registers the reference component that is used when loading images.
 void registerReferenceObject(java.lang.Object object)
          Registers the reference object that is used when loading images.
static boolean saveImageAsPNG(java.awt.image.RenderedImage image, java.io.OutputStream os)
          Saves the given image in File file using GIF -encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AWTImageOperations

public AWTImageOperations()
Private constructor to avoid instantiation.

Method Detail

registerReferenceComponent

public final void registerReferenceComponent(java.awt.Component component)
Registers the reference component that is used when loading images.

This Component can be any swing component, the reference is used for internally managing a MediaTracker.

Parameters:
component - the Component to use for loading.

registerReferenceObject

public final void registerReferenceObject(java.lang.Object object)
Registers the reference object that is used when loading images.

The images are loaded by means of the Class.getResource(java.lang.String) method. An image is specified by a name that is passed to this method. The method is invoked on a class object however, which delivers the beginning of the internally used url that specifies the absolute location of the image (or any resource in general). This method sets the class that is used for determing the beginning of the path.

Parameters:
object - the object to use as the beginning of the url path that is used for loading images.

registerReferenceClass

public final void registerReferenceClass(java.lang.Class refClass)
Registers the reference class that is used when loading images.

The images are loaded by means of the Class.getResource(java.lang.String) method. An image is specified by a name that is passed to this method. The method is invoked on a class object however, which delivers the beginning of the internally used url that specifies the absolute location of the image (or any resource in general). This method sets the class that is used for determing the beginning of the path.

Parameters:
refClass - the class to use as the beginning of the url path that is used for loading images.

loadImage

public final Raster loadImage(java.lang.String imagepath)
Loads the image from the source given by imagepath.

Specified by:
loadImage in interface ImageOperations
Parameters:
imagepath - the complete path of the image to load
Returns:
Image the loaded image

loadImageResource

public final Raster loadImageResource(java.lang.String imagepath)
Loads the image from the source given by imagepath.

Specified by:
loadImageResource in interface ImageOperations
Parameters:
imagepath - the complete path of the image to load
Returns:
Image the loaded image

loadImageResource

public final Raster loadImageResource(java.lang.Class referenceclass,
                                      java.lang.String imagepath)
Specified by:
loadImageResource in interface ImageOperations

loadImage

public final Raster loadImage(java.net.URL imagepath)
Specified by:
loadImage in interface ImageOperations

loadAWTImage

public final java.awt.Image loadAWTImage(java.lang.String imagepath)

loadAWTImageResource

public final java.awt.Image loadAWTImageResource(java.lang.String imagepath)

loadAWTImageResource

public final java.awt.Image loadAWTImageResource(java.lang.Class refClass,
                                                 java.lang.String imagepath)

loadAWTImage

public final java.awt.Image loadAWTImage(java.net.URL imagepath)

convertImageToRaster

public final Raster convertImageToRaster(java.awt.Image image)
Converts the Image given by image to a Raster object.

Parameters:
image - the Image to convert
Returns:
Raster the newly created Raster

canWriteFormat

public static boolean canWriteFormat(java.lang.String formatName)
Returns true if the specified format name can be written

Parameters:
formatName - the name of the format, for example gif.
Returns:
true iff the format can be written.

jpegEncode

public byte[] jpegEncode(int width,
                         int height,
                         int[] pixels,
                         float quality,
                         boolean forceBaseline)
Description copied from interface: ImageOperations
Encodes the given pixel data to JPEG data.

Specified by:
jpegEncode in interface ImageOperations
Parameters:
width - The width of the image
height - The height of the image
pixels - The pixel array width a size of width*height containing the colors encoded as 0xRRGGBB
quality - The JPEG quality (0.0f - 1.0f)
forceBaseline - The force baseline setting for the JPEG encoder
Returns:
The bytes of the JPEG file

saveImageAsPNG

public static boolean saveImageAsPNG(java.awt.image.RenderedImage image,
                                     java.io.OutputStream os)
Saves the given image in File file using GIF -encoding.
Notice: Only works with JDK1.4+.

Parameters:
image - the image to save.
os - The stream to write to
Returns:
true, if saving was successful.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.