public class ImageLoader extends 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 | Description |
---|---|---|
private static Vector |
fileExtensions |
|
private static Vector |
imageCodecClasses |
Modifier | Constructor | Description |
---|---|---|
private |
ImageLoader() |
Modifier and Type | Method | Description |
---|---|---|
static ImageCodec |
createCodec(int index) |
Creates an instance of one of the codec classes known to ImageLoader.
|
static 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(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() |
private static Vector fileExtensions
private static 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 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(File file) throws IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
file
- the file from which an image is to be loadednull
on failureIOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(File file, Vector listeners) throws IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
file
- the file to load an image fromlisteners
- a Vector of ProgressListener objects to be notifiedPixelImage
IOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(String fileName) throws IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
fileName
- name of the file from which an image is to be loadedIOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage load(String fileName, Vector listeners) throws IOException, InvalidFileStructureException, InvalidImageIndexException, UnsupportedTypeException
fileName
- name of the file from which an image is to be loadedlisteners
- a list of objects implementing ProgressListenerIOException
InvalidFileStructureException
InvalidImageIndexException
UnsupportedTypeException
public static PixelImage loadToolkitImageUri(String uri) throws 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()