Package org.eclipse.swt.graphics
Class ImageLoader
java.lang.Object
org.eclipse.swt.graphics.ImageLoader
Instances of this class are used to load images from,
and save images to, a file or stream.
Currently supported image formats are:
- BMP (Windows or OS/2 Bitmap)
- ICO (Windows Icon)
- JPEG
- GIF
- PNG
- TIFF
ImageLoaders
can be used to:
- load/save single images in all formats
- load/save multiple images (GIF/ICO/TIFF)
- load/save animated GIF images
- load interlaced GIF/PNG images
- load progressive JPEG images
- Since:
- 1.3
-
Field Summary
Modifier and TypeFieldDescriptionint
the background pixel for the logical screen (this corresponds to the GIF89a Background Color Index value).int
This is the compression used when saving jpeg and png files.the array of ImageData objects in this ImageLoader.int
the height of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Height value)int
the width of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Width value)int
the number of times to repeat the display of a sequence of animated images (this corresponds to the commonly-used GIF application extension for "NETSCAPE 2.0 01"). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addImageLoaderListener
(ImageLoaderListener listener) Adds the listener to the collection of listeners who will be notified when image data is either partially or completely loaded.boolean
Returnstrue
if the receiver has image loader listeners, andfalse
otherwise.load
(InputStream stream) Loads an array ofImageData
objects from the specified input stream.Loads an array ofImageData
objects from the file with the specified name.void
notifyListeners
(ImageLoaderEvent event) Notifies all image loader listeners that an image loader event has occurred.void
removeImageLoaderListener
(ImageLoaderListener listener) Removes the listener from the collection of listeners who will be notified when image data is either partially or completely loaded.void
save
(OutputStream stream, int format) Saves the image data in this ImageLoader to the specified stream.void
Saves the image data in this ImageLoader to a file with the specified name.
-
Field Details
-
data
the array of ImageData objects in this ImageLoader. This array is read in when the load method is called, and it is written out when the save method is called -
logicalScreenWidth
public int logicalScreenWidththe width of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Width value) -
logicalScreenHeight
public int logicalScreenHeightthe height of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Height value) -
backgroundPixel
public int backgroundPixelthe background pixel for the logical screen (this corresponds to the GIF89a Background Color Index value). The default is -1 which means 'unspecified background' -
repeatCount
public int repeatCountthe number of times to repeat the display of a sequence of animated images (this corresponds to the commonly-used GIF application extension for "NETSCAPE 2.0 01"). The default is 1. A value of 0 means 'display repeatedly' -
compression
public int compressionThis is the compression used when saving jpeg and png files.When saving jpeg files, the value is from 1 to 100, where 1 is very high compression but low quality, and 100 is no compression and high quality; default is 75.
When saving png files, the value is from 0 to 3, but they do not impact the quality because PNG is lossless compression. 0 is uncompressed, 1 is low compression and fast, 2 is default compression, and 3 is high compression but slow.
- Since:
- 3.1
-
-
Constructor Details
-
ImageLoader
public ImageLoader()Construct a new empty ImageLoader.
-
-
Method Details
-
load
Loads an array ofImageData
objects from the specified input stream. Throws an error if either an error occurs while loading the images, or if the images are not of a supported type. Returns the loaded image data array.- Parameters:
stream
- the input stream to load the images from- Returns:
- an array of
ImageData
objects loaded from the specified input stream - Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the stream is null
SWTException
-- ERROR_IO - if an IO error occurs while reading from the stream
- ERROR_INVALID_IMAGE - if the image stream contains invalid data
- ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
-
load
Loads an array ofImageData
objects from the file with the specified name. Throws an error if either an error occurs while loading the images, or if the images are not of a supported type. Returns the loaded image data array.- Parameters:
filename
- the name of the file to load the images from- Returns:
- an array of
ImageData
objects loaded from the specified file - Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the file name is null
SWTException
-- ERROR_IO - if an IO error occurs while reading from the file
- ERROR_INVALID_IMAGE - if the image file contains invalid data
- ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
-
save
Saves the image data in this ImageLoader to the specified stream. The format parameter can have one of the following values:IMAGE_BMP
- Windows BMP file format, no compression
IMAGE_BMP_RLE
- Windows BMP file format, RLE compression if appropriate
IMAGE_GIF
- GIF file format
IMAGE_ICO
- Windows ICO file format
IMAGE_JPEG
- JPEG file format
IMAGE_PNG
- PNG file format
- Parameters:
stream
- the output stream to write the images toformat
- the format to write the images in- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the stream is null
SWTException
-- ERROR_IO - if an IO error occurs while writing to the stream
- ERROR_INVALID_IMAGE - if the image data contains invalid data
- ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format
-
save
Saves the image data in this ImageLoader to a file with the specified name. The format parameter can have one of the following values:IMAGE_BMP
- Windows BMP file format, no compression
IMAGE_BMP_RLE
- Windows BMP file format, RLE compression if appropriate
IMAGE_GIF
- GIF file format
IMAGE_ICO
- Windows ICO file format
IMAGE_JPEG
- JPEG file format
IMAGE_PNG
- PNG file format
- Parameters:
filename
- the name of the file to write the images toformat
- the format to write the images in- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the file name is null
SWTException
-- ERROR_IO - if an IO error occurs while writing to the file
- ERROR_INVALID_IMAGE - if the image data contains invalid data
- ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format
-
addImageLoaderListener
Adds the listener to the collection of listeners who will be notified when image data is either partially or completely loaded.An ImageLoaderListener should be added before invoking one of the receiver's load methods. The listener's
imageDataLoaded
method is called when image data has been partially loaded, as is supported by interlaced GIF/PNG or progressive JPEG images.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
- See Also:
-
removeImageLoaderListener
Removes the listener from the collection of listeners who will be notified when image data is either partially or completely loaded.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
- See Also:
-
hasListeners
public boolean hasListeners()Returnstrue
if the receiver has image loader listeners, andfalse
otherwise.- Returns:
true
if there areImageLoaderListener
s, andfalse
otherwise- See Also:
-
notifyListeners
Notifies all image loader listeners that an image loader event has occurred. Pass the specified event object to each listener.- Parameters:
event
- theImageLoaderEvent
to send to eachImageLoaderListener
-