public class ToolkitLoader
extends java.lang.Object
Image
using
Toolkit
's built-in loading capabilities and
converts it to RGB24Image
using
ImageCreator
.
Supported file formats are JPEG and GIF. PNG is supported since Java 1.3. I have heard that XBM are supposedly loaded as well. I don't know that format and haven't tested this functionality.
In addition, this class can also use JIU's built-in codecs from this class.
Toolkit
class:
RGB24Image rgbImage = ToolkitLoader.loadAsRgb24Image("flower.jpg");This will only load images from files in formats that are supported by Toolkit - normally, that only includes JPEG, GIF and since Java 1.3 PNG. A potential problem of this approach is that Toolkit always delivers RGB data, even if the image file only contains a black and white image. In order to get an image object of the "real" type, try JIU's
AutoDetectColorType
with
rgbImage
(if you follow the link you will get a usage example
for that class as well).
System.exit(0);
.Modifier and Type | Field and Description |
---|---|
private static java.awt.Frame |
frame |
Modifier | Constructor and Description |
---|---|
private |
ToolkitLoader()
This class has only static methods and fields, so there is no need to instantiate it.
|
Modifier and Type | Method and Description |
---|---|
static java.awt.Image |
load(java.lang.String fileName)
Loads an image from a file using the AWT's built-in loader.
|
static RGB24Image |
loadAsRgb24Image(java.lang.String fileName)
Loads an image from a file using the AWT's built-in loader and
converts the image to a
RGB24Image
object. |
static PixelImage |
loadViaToolkitOrCodecs(java.lang.String fileName)
Attempts to load an image from a file given by its name,
using both the JIU codecs and the image loading functionality in
java.awt.Toolkit.
|
static PixelImage |
loadViaToolkitOrCodecs(java.lang.String fileName,
boolean preferToolkit,
java.util.Vector progressListeners)
Attempts to load an image from a file given by its name,
using both the JIU codecs and the image loading functionality in
java.awt.Toolkit.
|
private ToolkitLoader()
public static java.awt.Image load(java.lang.String fileName)
Image
object.
This method does nothing more than call Toolkit.getImage(String)
,
wait for it using a MediaTracker
and return
the resulting image.fileName
- name of the image filepublic static RGB24Image loadAsRgb24Image(java.lang.String fileName)
RGB24Image
object.
First calls load(java.lang.String)
with the filename, then converts
the loaded image using ImageCreator.convertImageToRGB24Image(java.awt.Image)
.fileName
- name of the file from which the image is to be loadedRGB24Image
public static PixelImage loadViaToolkitOrCodecs(java.lang.String fileName)
loadViaToolkitOrCodecs(fileName, false);
.fileName
- name of the image filenull
on failurepublic static PixelImage loadViaToolkitOrCodecs(java.lang.String fileName, boolean preferToolkit, java.util.Vector progressListeners)
loadAsRgb24Image(java.lang.String)
from this class for Toolkit loading
and ImageLoader
for JIU's codecs.fileName
- name of the image filenull
on failure