net.sourceforge.jiu.codecs
Class ImageLoader
java.lang.Object
net.sourceforge.jiu.codecs.ImageLoader
public class ImageLoader
extends java.lang.Object
A convenience class with static methods to load images from files using JIU codecs.
The load methods of this class try to load an image with all codecs registered with this class.
This includes almost every codec that resides in the
net.sourceforge.jiu.codecs
package.
You can register additional codecs with
registerCodecClass(ImageCodec)
or remove the usage
of codecs with
removeCodecClass(ImageCodec)
.
A Codec that cannot safely identify a file to be in the format that it supports must not be used with ImageLoader.
The failure to identify typically comes from the lack of magic byte sequences defined for the format.
In order to load such a file, use the codec manually.
Example:
PalmCodec
.
In order to load an image via
java.awt.Toolkit
(JPEG, PNG or GIF), use
ToolkitLoader
.
It combines the loading features of java.awt.Toolkit and JIU's ImageLoader.
Usage example
PixelImage image = null;
try
{
image = ImageLoader.load("image.tif");
}
catch (Exception e)
{
// handle exception
}
static ImageCodec | createCodec(int index) - Creates an instance of one of the codec classes known to ImageLoader.
|
static FilenameFilter | createFilenameFilter() - Returns a filename filter (
java.io.FilenameFilter ) that accepts files
with name extensions typical for the image file formats known to ImageLoader.
|
static int | getNumCodecs() - Returns the number of codec classes currently known to ImageLoader.
|
static PixelImage | load(File file) - Attempts to load an image from a file.
|
static PixelImage | load(File file, Vector listeners) - Attempts to load an image from a file, notifying the
argument progress listeners.
|
static PixelImage | load(String fileName) - Load an image from a file given by its name.
|
static PixelImage | load(String fileName, Vector listeners) - Attempts to load an image from the file with the given name,
using the given list of progress listeners.
|
static PixelImage | loadToolkitImageUri(String uri)
|
static void | registerCodecClass(ImageCodec codec) - Registers a codec class with ImageLoader.
|
static void | removeAllCodecClasses() - Removes all codec classes from the internal list of codec classes.
|
static void | removeCodecClass(ImageCodec codec) - Removes a codec class from the internal list of codec classes.
|
private static void | updateFileExtensions()
|
fileExtensions
private static Vector fileExtensions
imageCodecClasses
private static Vector imageCodecClasses
ImageLoader
private ImageLoader()
createCodec
public static ImageCodec createCodec(int index)
Creates an instance of one of the codec classes known to ImageLoader.
index
- 0-based index of codec number, maximum value is getNumCodecs()
- 1
- new codec object or
null
if no object could be instantiated
createFilenameFilter
public static FilenameFilter createFilenameFilter()
Returns a filename filter (
java.io.FilenameFilter
) that accepts files
with name extensions typical for the image file formats known to ImageLoader.
The filter could then be used in an file dialog like
java.awt.FileDialog
.
Note that this filter does not include file formats supported by the AWT
java.awt.Toolkit
(GIF and JPEG, also PNG since Java 1.3).
- filter for image file names
getNumCodecs
public static int getNumCodecs()
- number of known codec classes
registerCodecClass
public static void registerCodecClass(ImageCodec codec)
Registers a codec class with ImageLoader.
The argument is an instance of the class to be registered.
Note that the codec class must have an empty constructor.
Example: let's say you have written a new codec called ACMEImageCodec.
Your codec supports loading images.
Then you could register it like that:
ImageLoader.registerCodecClass(new ACMEImageCodec());
codec
- an instance of the codec class to be registered
removeAllCodecClasses
public static void removeAllCodecClasses()
Removes all codec classes from the internal list of codec classes.
After a call to this method, ImageLoader will not load anything unless
new codecs get registered.
removeCodecClass
public static void removeCodecClass(ImageCodec codec)
Removes a codec class from the internal list of codec classes.
codec
- an instance of the codec class to be removed
updateFileExtensions
private static void updateFileExtensions()