|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.awt.ImageUtility
public class ImageUtility
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.
| 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 |
|---|
public ImageUtility()
| Method Detail |
|---|
public static ImageProducer getImageProducer(String resource)
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.
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.
ImageProducer object if successfully
loaded, null if not.getImage(String)public static Image getImage(String resource)
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).
resource - The name of the resource (file, URL, Java resource) to load
the image from (see getImageProducer(java.lang.String) for details).
Image object if successfully loaded, null if not.getImageProducer(String)
public static Image getImage(String resource,
Component ac)
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.
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.
Image object if successfully loaded, null if not.getImage(String)
public static Image loadImage(Image im,
Component ac)
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).
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.
Image object if successfully loaded, null if not.getImage(String)public static Image getImage(ImageProducer ip)
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.
ip - A standard ImageProducer which is
capable of producing an image. May be null - but you'll get
null back.
Image object if successfully loaded, null if not.getImageProducer(java.lang.String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||