com.ccg.awt
Class ImageUtility

java.lang.Object
  extended by com.ccg.awt.ImageUtility

public class ImageUtility
extends Object

Generic utilites to use while working with Image objects.

It turned out to be rather awkward to load GIF/JPG images directly using standard Java methods. The Applet clas provides methods for this, but this didn't help when one wanted to write full Java applications. After investigation of various resources and looking through the source code, I decided it would would be easier for me to have a static helper function to load GIF/JPG images in a standard way. That is the reason this class was originally started.

Other "handy" and "generic" image methods are likely to be added as the need arises.

To see how to use this class, refer to the ImageDemo.java example program which you can run from the command line.

Since:
1.0
Version:
$Revision: 1.5 $
Author:
$Author: pkb $
See Also:
ImageDemo.java

Constructor Summary
ImageUtility()
           
 
Method Summary
static Image getImage(ImageProducer ip)
          Get a Image from a ImageProducer This method is used to create a Image object from its associated ImageProducer.
static Image getImage(String resource)
          Get a Image specified by a simple String.
static Image getImage(String resource, Component ac)
          Get and LOAD Image specified by a simple String.
static ImageProducer getImageProducer(String resource)
          Get a ImageProducer specified by a simple String.
static Image loadImage(Image im, Component ac)
          Force loading a Image object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtility

public ImageUtility()
Method Detail

getImageProducer

public static ImageProducer getImageProducer(String resource)
Get a ImageProducer specified by a simple String. This method does its best to load a image from its specified source. This method allows one to do things like the following:

The resource name passed determines how we search for the image file. The rules are as follows:

If all of the above fail to find/load the associated ImageProducer for the resource, then null will be returned.

You may prefer to use getImage(String) which returns the associated Image for the resource directly instead of the ImageProducer as this method does.

Use of this method will disable code from being used in a Applet - the getImage(String) method should be used instead.

Parameters:
resource - The name of the resource (file, URL, Java resource) to load as specified above. You can also safely pass null - but you'll get null back.
Returns:
ImageProducer object if successfully loaded, null if not.
Since:
1.0
See Also:
getImage(String)

getImage

public static Image getImage(String resource)
Get a Image specified by a simple String. This method is a wrapper around the getImageProducer(String) method and is very useful if one wants to load a GIF/JPG images based on a name (file name, URL, resource) of the image source. This method works in standard JVM's (at least IBM 1.1.8 and Sun 1.2.2).

Parameters:
resource - The name of the resource (file, URL, Java resource) to load the image from (see getImageProducer(java.lang.String) for details).
Returns:
Image object if successfully loaded, null if not.
Since:
1.0
See Also:
getImageProducer(String)

getImage

public static Image getImage(String resource,
                             Component ac)
Get and LOAD Image specified by a simple String. This method is a wrapper around the getImageProducer(String) method and is very useful if one wants to load a GIF/JPG images based on a name (file name, URL, resource) of the image source. This method works in standard JVM's (at least IBM 1.1.8 and Sun 1.2.2). This method forces the image to be loaded immediately (it creates a MediaTracker and forces the image to be loaded immediately).

This method is more convienent when you want to force your image to be loaded, but is less efficient than providing your own MediaTracker object to load your images with.

Parameters:
resource - The name of the resource (file, URL, Java resource) to load the image from (see getImageProducer(java.lang.String) for details).
ac - A standard Component. Must not be null, and is required in order to force the loading of the resource.
Returns:
Image object if successfully loaded, null if not.
Since:
1.0
See Also:
getImage(String)

loadImage

public static Image loadImage(Image im,
                              Component ac)
Force loading a Image object.

This method is more convienent when you want to force your image to be loaded, but is less efficient than providing your own MediaTracker object to load your images with (because a new MediaTracker is created each time you use this method).

Parameters:
im - The Image object you wish to make sure is loaded.
ac - A standard Component. Must not be null, and is required in order to force the loading of the resource.
Returns:
Image object if successfully loaded, null if not.
Since:
1.0
See Also:
getImage(String)

getImage

public static Image getImage(ImageProducer ip)
Get a Image from a ImageProducer This method is used to create a Image object from its associated ImageProducer. This method does not throw any exceptions, but may return null if the producer fails to produce a image.

Parameters:
ip - A standard ImageProducer which is capable of producing an image. May be null - but you'll get null back.
Returns:
Image object if successfully loaded, null if not.
Since:
1.0
See Also:
getImageProducer(java.lang.String)


Copyright 1998-1998-2006 null. All Rights Reserved.