org.eclipse.swt.graphics
Class Image

java.lang.Object
  |
  +--org.eclipse.swt.graphics.Image

public final class Image
extends Object

Instances of this class are graphics which have been prepared for display on a specific device. That is, they are ready to paint using methods such as GC.drawImage() and display on widgets with, for example, Button.setImage().

If loaded from a file format that supports it, an Image may have transparency, meaning that certain pixels are specified as being transparent when drawn. Examples of file formats that support transparency are GIF and PNG.

There are two primary ways to use Images. The first is to load a graphic file from disk and create an Image from it. This is done using an Image constructor, for example:

      Image i = new Image(device, "C:\\graphic.bmp");
   
A graphic file may contain a color table specifying which colors the image was intended to possess. In the above example, these colors will be mapped to the closest available color in SWT. It is possible to get more control over the mapping of colors as the image is being created, using code of the form:
      ImageData data = new ImageData("C:\\graphic.bmp"); 
      RGB[] rgbs = data.getRGBs(); 
      // At this point, rgbs contains specifications of all
      // the colors contained within this image. You may
      // allocate as many of these colors as you wish by
      // using the Color constructor Color(RGB), then
      // create the image:
      Image i = new Image(device, data);
   

Applications which require even greater control over the image loading process should use the support provided in class ImageLoader.

Application code must explicitely invoke the Image.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

See Also:
Color, ImageData, ImageLoader

Constructor Summary
Image(Device device, int width, int height)
          Constructs a new instance of an Image (empty image).
Image(Device device, String filename)
          Constructs a new instance by loading the Image from the file with the specified name.
 
Method Summary
 boolean isDisposed()
          This method returns the dispose state for the image.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, toString
 

Constructor Detail

Image

public Image(Device device,
             String filename)
Constructs a new instance by loading the Image from the file with the specified name. Throws an error if the file cannot be loaded, or the image type is not unsupported. This constructor is provided for convenience when loading a single image only. If the specified file contains multiple images, only the first one will be loaded.

Parameters:
device - - the device on which the image is being created
filename - - the name of the file with the image data

Image

public Image(Device device,
             int width,
             int height)
Constructs a new instance of an Image (empty image).

Parameters:
device - - the device on which the image is being created
width - - dimension of the Image
height - - dimension of the Image
Method Detail

isDisposed

public boolean isDisposed()
This method returns the dispose state for the image. When an image has been disposed, it is an error to invoke any other method using the image.

Returns:
true when the image is disposed and false otherwise.