Top Description Fields Constructors Methods
org.eclipse.swt.graphics

public Class ImageLoader

extends Object
Class Inheritance
Imports
java.io.*, java.util.*, .List, org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.image.*, org.eclipse.swt.widgets.*

Instances of this class are used to load images from, and save images to, a file or stream.

Currently supported image formats are:

ImageLoaders can be used to:

Note

ImageLoader is implemented in Java on some platforms, which has certain performance implications. Performance and memory sensitive applications may benefit from using one of the constructors provided by Image, as these are implemented natively.

See Also
SWT Example: ImageAnalyzer, Sample code and further information

Field Summary

Modifier and TypeField and Description
public int
backgroundPixel

the background pixel for the logical screen (this corresponds to the GIF89a Background Color Index value).

public int
compression

This is the compression used when saving jpeg and png files.

public ImageData[]
data

the array of ImageData objects in this ImageLoader.

pack-priv List<ImageLoaderListener>
public int
logicalScreenHeight

the height of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Height value)

public int
logicalScreenWidth

the width of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Width value)

pack-priv static final int
PNG_INTERLACE_METHOD_OFFSET

If the 29th byte of the PNG file is not zero, then it is interlaced.

public int
repeatCount

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

AccessConstructor and Description
public
ImageLoader()

Construct a new empty ImageLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addImageLoaderListener(ImageLoaderListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when image data is either partially or completely loaded.

pack-priv static long
gdk_pixbuf_new_from_file(String filename)

Returns GdkPixbuf pointer by loading an image from filename (Java string)

pack-priv ImageData[]
pack-priv int
getImageFormat(long loader)

Return the type of file from which the image was read by inspecting GdkPixbufFormat from GdkPixbufLoader It is expressed as 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
public boolean

Returns:

true if there are ImageLoaderListeners, and false otherwise
hasListeners
()

Returns true if the receiver has image loader listeners, and false otherwise.

pack-priv boolean

Returns:

true iff 29th byte of PNG files is not zero
isInterlacedPNG
(byte[] imageAsByteArray)

Return true if the image is an interlaced PNG file.

public ImageData[]

Returns:

an array of ImageData objects loaded from the specified input stream
load
(InputStream
the input stream to load the images from
stream
)

Loads an array of ImageData objects from the specified input stream.

public ImageData[]

Returns:

an array of ImageData objects loaded from the specified file
load
(String
the name of the file to load the images from
filename
)

Loads an array of ImageData objects from the file with the specified name.

pack-priv ImageData[]
loadFromFile(String filename)

Load GdkPixbuf directly using gdk_pixbuf_new_from_file, without FileInputStream.

public void
notifyListeners(ImageLoaderEvent
the ImageLoaderEvent to send to each ImageLoaderListener
event
)

Notifies all image loader listeners that an image loader event has occurred.

pack-priv static ImageData

Returns:

ImageData with pixbuf data
pixbufToImageData
(long pixbuf)

Convert GdkPixbuf pointer to Java object ImageData

public void
removeImageLoaderListener(ImageLoaderListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when image data is either partially or completely loaded.

pack-priv void
reset()

Resets the fields of the ImageLoader, except for the imageLoaderListeners field.

public void
save(OutputStream
the output stream to write the images to
stream
,
int
the format to write the images in
format
)

Saves the image data in this ImageLoader to the specified stream.

public void
save(String
the name of the file to write the images to
filename
,
int
the format to write the images in
format
)

Saves the image data in this ImageLoader to a file with the specified name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundPixelback to summary
public int backgroundPixel

the background pixel for the logical screen (this corresponds to the GIF89a Background Color Index value). The default is -1 which means 'unspecified background'

compressionback to summary
public int compression

This 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.8
databack to summary
public ImageData[] 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

imageLoaderListenersback to summary
pack-priv List<ImageLoaderListener> imageLoaderListeners
logicalScreenHeightback to summary
public int logicalScreenHeight

the height of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Height value)

logicalScreenWidthback to summary
public int logicalScreenWidth

the width of the logical screen on which the images reside, in pixels (this corresponds to the GIF89a Logical Screen Width value)

PNG_INTERLACE_METHOD_OFFSETback to summary
pack-priv static final int PNG_INTERLACE_METHOD_OFFSET

If the 29th byte of the PNG file is not zero, then it is interlaced.

repeatCountback to summary
public int repeatCount

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"). The default is 1. A value of 0 means 'display repeatedly'

Constructor Detail

ImageLoaderback to summary
public ImageLoader()

Construct a new empty ImageLoader.

Method Detail

addImageLoaderListenerback to summary
public void addImageLoaderListener(ImageLoaderListener listener)

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:ImageLoaderListener

the listener which should be notified

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the listener is null
See Also
ImageLoaderListener, ImageLoaderEvent
gdk_pixbuf_new_from_fileback to summary
pack-priv static long gdk_pixbuf_new_from_file(String filename)

Returns GdkPixbuf pointer by loading an image from filename (Java string)

getImageDataArrayFromStreamback to summary
pack-priv ImageData[] getImageDataArrayFromStream(InputStream stream)
getImageFormatback to summary
pack-priv int getImageFormat(long loader)

Return the type of file from which the image was read by inspecting GdkPixbufFormat from GdkPixbufLoader It is expressed as 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
hasListenersback to summary
public boolean hasListeners()

Returns true if the receiver has image loader listeners, and false otherwise.

Returns:boolean

true if there are ImageLoaderListeners, and false otherwise

See Also
addImageLoaderListener(ImageLoaderListener), removeImageLoaderListener(ImageLoaderListener)
isInterlacedPNGback to summary
pack-priv boolean isInterlacedPNG(byte[] imageAsByteArray)

Return true if the image is an interlaced PNG file. This is used to check whether ImageLoaderEvent should be fired when loading images.

Returns:boolean

true iff 29th byte of PNG files is not zero

loadback to summary
public ImageData[] load(InputStream stream)

Loads an array of ImageData 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:InputStream

the input stream to load the images from

Returns:ImageData[]

an array of ImageData objects loaded from the specified input stream

Exceptions
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
loadback to summary
public ImageData[] load(String filename)

Loads an array of ImageData 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:String

the name of the file to load the images from

Returns:ImageData[]

an array of ImageData objects loaded from the specified file

Exceptions
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
loadFromFileback to summary
pack-priv ImageData[] loadFromFile(String filename)

Load GdkPixbuf directly using gdk_pixbuf_new_from_file, without FileInputStream.

notifyListenersback to summary
public void notifyListeners(ImageLoaderEvent event)

Notifies all image loader listeners that an image loader event has occurred. Pass the specified event object to each listener.

Parameters
event:ImageLoaderEvent

the ImageLoaderEvent to send to each ImageLoaderListener

pixbufToImageDataback to summary
pack-priv static ImageData pixbufToImageData(long pixbuf)

Convert GdkPixbuf pointer to Java object ImageData

Returns:ImageData

ImageData with pixbuf data

removeImageLoaderListenerback to summary
public 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.

Parameters
listener:ImageLoaderListener

the listener which should no longer be notified

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the listener is null
See Also
addImageLoaderListener(ImageLoaderListener)
resetback to summary
pack-priv void reset()

Resets the fields of the ImageLoader, except for the imageLoaderListeners field.

saveback to summary
public void save(OutputStream stream, int format)

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:OutputStream

the output stream to write the images to

format:int

the format to write the images in

Exceptions
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
saveback to summary
public void save(String filename, int format)

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:String

the name of the file to write the images to

format:int

the format to write the images in

Exceptions
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