|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.javaranch.common.ImageLoader
This class helps you load images before you use them.
Java allows you to show parts of an image before the whole image is loaded. This class forces the entire image to be loaded before you attempt to use it.
- - - - - - - - - - - - - - - - -
Copyright (c) 1998-2004 Paul Wheaton
You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...
My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.
The original source can be found at JavaRanch
- - - - - - - - - - - - - - - - -
Constructor Summary | |
ImageLoader()
|
Method Summary | |
static java.awt.Image |
get(byte[] imageBytes)
Pass in a GIF or JPEG image stored as a byte array and get a Java Image object back. |
static java.awt.Image |
get(java.lang.Object obj,
java.lang.String where)
Pass in an object and a relative filename and the image will be pulled up relative to where the class came from. |
static java.awt.Image |
get(java.lang.String where)
Pass in a filename or URL and get an image back. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ImageLoader()
Method Detail |
public static java.awt.Image get(byte[] imageBytes)
public static java.awt.Image get(java.lang.String where)
If the name starts with "file:", "jar:" or "http:", the string will first be converted to a URL before getting the object. Otherwise, the string is assumed to be a filename.
public static java.awt.Image get(java.lang.Object obj, java.lang.String where)
Suppose you have a class called com.cows.MooPanel. And in the constructor you want to load your image conveniently located at com/cows/images/mooing_cow.jpg. This image sits in the subdirectory which sits in the same directory as the com.cows.MooPanel class! But is your class being used from a jar file? Over the internet? Worry no more! This method will load your image through the same pipe that the class was loaded. In this example, call ImageLoader.get( this , "images/mooing_cow.jpg" );
obj
- The address for the image you are looking for is relative to this object. where
- The address for the image you are looking for relative to the given object.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |