public class ImageLoader
extends java.lang.Object
net.sourceforge.jiu.codecs
package.
You can register additional codecs with registerCodecClass(net.sourceforge.jiu.codecs.ImageCodec)
or remove the usage
of codecs with removeCodecClass(net.sourceforge.jiu.codecs.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 Toolkit
(JPEG, PNG or GIF), use
ToolkitLoader
.
It combines the loading features of java.awt.Toolkit and JIU's ImageLoader.
PixelImage image = null; try { image = ImageLoader.load("image.tif"); } catch (Exception e) { // handle exception }
Modifier and Type | Field and Description |
---|---|
private static java.util.Vector |
fileExtensions |
private static java.util.Vector |
imageCodecClasses |
Modifier | Constructor and Description |
---|---|
private |
ImageLoader() |
Modifier and Type | Method and Description |
---|---|
static ImageCodec |
createCodec(int index)
Creates an instance of one of the codec classes known to ImageLoader.
|
static java.io.FilenameFilter |
createFilenameFilter()
Returns a filename filter (
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(java.io.File file)
Attempts to load an image from a file.
|
static PixelImage |
load(java.io.File file,
java.util.Vector listeners)
Attempts to load an image from a file, notifying the
argument progress listeners.
|
static PixelImage |
load(java.lang.String fileName)
Load an image from a file given by its name.
|
static PixelImage |
load(java.lang.String fileName,
java.util.Vector listeners)
Attempts to load an image from the file with the given name,
using the given list of progress listeners.
|
static PixelImage |
loadToolkitImageUri(java.lang.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() |
private static java.util.Vector fileExtensions
private static java.util.Vector imageCodecClasses
public static ImageCodec createCodec(int index)
index
- 0-based index of codec number, maximum value is getNumCodecs()
- 1
null
if no object could be instantiatedpublic static java.io.FilenameFilter createFilenameFilter()
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 FileDialog
.
Note that this filter does not include file formats supported by the AWT
Toolkit
(GIF and JPEG, also PNG since Java 1.3).
public static int getNumCodecs()
registerCodecClass(net.sourceforge.jiu.codecs.ImageCodec)
)
or by removing codec classes (removeCodecClass(net.sourceforge.jiu.codecs.ImageCodec)
).public static PixelImage load(java.io.File file) throws java.io.IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
file
- the file from which an image is to be loadednull
on failurejava.io.IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(java.io.File file, java.util.Vector listeners) throws java.io.IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
file
- the file to load an image fromlisteners
- a Vector of ProgressListener objects to be notifiedPixelImage
java.io.IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(java.lang.String fileName) throws java.io.IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
fileName
- name of the file from which an image is to be loadedjava.io.IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(java.lang.String fileName, java.util.Vector listeners) throws java.io.IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
fileName
- name of the file from which an image is to be loadedlisteners
- a list of objects implementing ProgressListenerjava.io.IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage loadToolkitImageUri(java.lang.String uri) throws java.io.IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
java.io.IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static void registerCodecClass(ImageCodec codec)
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 registeredpublic static void removeAllCodecClasses()
public static void removeCodecClass(ImageCodec codec)
codec
- an instance of the codec class to be removedprivate static void updateFileExtensions()