Eclipse Rich Ajax Platform
Release 1.3

org.eclipse.swt.graphics
Class Image

java.lang.Object
  extended byorg.eclipse.swt.graphics.Resource
      extended byorg.eclipse.swt.graphics.Image

public final class Image
extends Resource

Instances of this class are graphics which have been prepared for display on a specific device. That is, they are to 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.

In RWT, images are shared among all sessions. Therefore they lack a public constructor. Images can be created using the getImage() methods of class Graphics

See Also:
Graphics.getImage(String), Graphics.getImage(String, ClassLoader), Graphics.getImage(String, java.io.InputStream)

Field Summary
 String resourceName
          IMPORTANT: This field is not part of the SWT public API.
 
Constructor Summary
Image(Device device, InputStream stream)
          Constructs an instance of this class by loading its representation from the specified input stream.
Image(Device device, String fileName)
          Constructs an instance of this class by loading its representation from the file with the specified name.
 
Method Summary
 Rectangle getBounds()
          Returns the bounds of the receiver.
 
Methods inherited from class org.eclipse.swt.graphics.Resource
dispose, getDevice, isDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourceName

public String resourceName
IMPORTANT: This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

Constructor Detail

Image

public Image(Device device,
             InputStream stream)
Constructs an instance of this class by loading its representation from the specified input stream. Throws an error if an error occurs while loading the image, or if the result is an image of an unsupported type. Application code is still responsible for closing the input stream.

This constructor is provided for convenience when loading a single image only. If the stream contains multiple images, only the first one will be loaded. To load multiple images, use ImageLoader.load().

This constructor may be used to load a resource as follows:

     static Image loadImage (Display display, Class clazz, String string) {
          InputStream stream = clazz.getResourceAsStream (string);
          if (stream == null) return null;
          Image image = null;
          try {
               image = new Image (display, stream);
          } catch (SWTException ex) {
          } finally {
               try {
                    stream.close ();
               } catch (IOException ex) {}
          }
          return image;
     }
 

Note, this constructor is provided for convenience when single-sourcing code with SWT. For RWT, the recommended way to create images is to use one of the Graphics#getImage() methods.

Parameters:
device - the device on which to create the image
stream - the input stream to load the image from
Throws:
IllegalArgumentException -
SWTException -
SWTError -
Since:
1.3
See Also:
Graphics.getImage(String), Graphics.getImage(String, ClassLoader), Graphics.getImage(String, java.io.InputStream)

Image

public Image(Device device,
             String fileName)
Constructs an instance of this class by loading its representation from the file with the specified name. Throws an error if an error occurs while loading the image, or if the result is an image of an unsupported type.

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 used.

Parameters:
device - the device on which to create the image
Throws:
IllegalArgumentException -
SWTException -
SWTError -
Since:
1.3
See Also:
Graphics.getImage(String), Graphics.getImage(String, ClassLoader), Graphics.getImage(String, java.io.InputStream)
Method Detail

getBounds

public Rectangle getBounds()
Returns the bounds of the receiver. The rectangle will always have x and y values of 0, and the width and height of the image.

Returns:
a rectangle specifying the image's bounds
Throws:
SWTException -
  • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon

Eclipse Rich Ajax Platform
Release 1.3

Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2009. All rights reserved.