org.eclipse.swt.graphics
Class Image

java.lang.Object
  |
  +--org.eclipse.swt.graphics.Image
All Implemented Interfaces:
Drawable

public final class Image
extends Object
implements Drawable

Safe:


Field Summary
(package private)  int alpha
          the global alpha value to be used for every pixel (Warning: This field is platform dependent)
(package private)  byte[] alphaData
          the alpha data for the image (Warning: This field is platform dependent)
(package private)  ImageData data
          the image data used to create this image if it is a icon.
(package private) static int DEFAULT_SCANLINE_PAD
          specifies the default scanline padding (Warning: This field is platform dependent)
(package private)  Device device
          the device where this image was created
 int handle
          Suppressed: the OS resource of the image (Warning: This field is platform dependent)
(package private)  GC memGC
          the GC which is drawing on the image (Warning: This field is platform dependent)
(package private)  int transparentPixel
          specifies the transparent pixel (Warning: This field is platform dependent)
 int type
          Enabled: specifies whether the receiver is a bitmap or an icon (one of SWT.BITMAP, SWT.ICON)
 
Constructor Summary
(package private) Image()
          Prevents uninitialized instances from being created outside the package.
  Image(Device device, ImageData data)
          Enabled: Constructs an instance of this class from the given ImageData.
  Image(Device device, ImageData source, ImageData mask)
          Enabled: Constructs an instance of this class, whose type is SWT.ICON, from the two given ImageData objects.
  Image(Device device, Image srcImage, int flag)
          Enabled: Constructs a new instance of this class based on the provided image, with an appearance that varies depending on the value of the flag.
  Image(Device device, InputStream stream)
          Enabled: Constructs an instance of this class by loading its representation from the specified input stream.
  Image(Device device, int width, int height)
          Enabled: Constructs an empty instance of this class with the specified width and height.
  Image(Device device, Rectangle bounds)
          Enabled: Constructs an empty instance of this class with the width and height of the specified rectangle.
  Image(Device device, String filename)
          Suppressed: Constructs an instance of this class by loading its representation from the file with the specified name.
 
Method Summary
(package private)  int createDIBFromDDB(int hDC, int hBitmap, int width, int height)
          Create a DIB from a DDB without using GetDIBits.
 void dispose()
          Enabled: Disposes of the operating system resources associated with the image.
 boolean equals(Object object)
          Suppressed: Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
 Color getBackground()
          Enabled: Returns the color to which to map the transparent pixel, or null if the receiver has no transparent pixel.
 Rectangle getBounds()
          Enabled: Returns the bounds of the receiver.
(package private) static void GetIconInfo(Image image, org.eclipse.swt.internal.win32.ICONINFO info)
          Feature in WinCE.
 ImageData getImageData()
          Enabled: Returns an ImageData based on the receiver Modifications made to this ImageData will not affect the Image.
 int hashCode()
          Suppressed: Returns an integer hash code for the receiver.
(package private)  void init(Device device, ImageData i)
           
(package private) static int[] init(Device device, Image image, ImageData i)
           
(package private)  void init(Device device, int width, int height)
           
 void internal_dispose_GC(int hDC, GCData data)
          Suppressed: Invokes platform specific functionality to dispose a GC handle.
 int internal_new_GC(GCData data)
          Suppressed: Invokes platform specific functionality to allocate a new GC handle.
 boolean isDisposed()
          Enabled: Returns true if the image has been disposed, and false otherwise.
 void setBackground(Color color)
          Enabled: Sets the color to which to map the transparent pixel.
 String toString()
          Suppressed: Returns a string containing a concise, human-readable description of the receiver.
static Image win32_new(Device device, int type, int handle)
          Suppressed: Invokes platform specific functionality to allocate a new image.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public int type
Enabled: specifies whether the receiver is a bitmap or an icon (one of SWT.BITMAP, SWT.ICON)


handle

public int handle
Suppressed: the OS resource of the image (Warning: This field is platform dependent)


device

Device device
the device where this image was created


transparentPixel

int transparentPixel
specifies the transparent pixel (Warning: This field is platform dependent)


memGC

GC memGC
the GC which is drawing on the image (Warning: This field is platform dependent)


alphaData

byte[] alphaData
the alpha data for the image (Warning: This field is platform dependent)


alpha

int alpha
the global alpha value to be used for every pixel (Warning: This field is platform dependent)


data

ImageData data
the image data used to create this image if it is a icon. Used only in WinCE (Warning: This field is platform dependent)


DEFAULT_SCANLINE_PAD

static final int DEFAULT_SCANLINE_PAD
specifies the default scanline padding (Warning: This field is platform dependent)

Constructor Detail

Image

Image()
Prevents uninitialized instances from being created outside the package.


Image

public Image(Device device,
             int width,
             int height)
Enabled: Constructs an empty instance of this class with the specified width and height. The result may be drawn upon by creating a GC and using any of its drawing operations, as shown in the following example:
    Image i = new Image(device, width, height);
    GC gc = new GC(i);
    gc.drawRectangle(0, 0, 50, 50);
    gc.dispose();
 

Note: Some platforms may have a limitation on the size of image that can be created (size depends on width, height, and depth). For example, Windows 95, 98, and ME do not allow images larger than 16M.

Parameters:
device - the device on which to create the image
width - the width of the new image
height - the height of the new image

Image

public Image(Device device,
             Image srcImage,
             int flag)
Enabled: Constructs a new instance of this class based on the provided image, with an appearance that varies depending on the value of the flag. The possible flag values are:
IMAGE_COPY
the result is an identical copy of srcImage
IMAGE_DISABLE
the result is a copy of srcImage which has a disabled look
IMAGE_GRAY
the result is a copy of srcImage which has a gray scale look

Parameters:
device - the device on which to create the image
srcImage - the image to use as the source
flag - the style, either IMAGE_COPY, IMAGE_DISABLE or IMAGE_GRAY

Image

public Image(Device device,
             Rectangle bounds)
Enabled: Constructs an empty instance of this class with the width and height of the specified rectangle. The result may be drawn upon by creating a GC and using any of its drawing operations, as shown in the following example:
    Image i = new Image(device, boundsRectangle);
    GC gc = new GC(i);
    gc.drawRectangle(0, 0, 50, 50);
    gc.dispose();
 

Note: Some platforms may have a limitation on the size of image that can be created (size depends on width, height, and depth). For example, Windows 95, 98, and ME do not allow images larger than 16M.

Parameters:
device - the device on which to create the image
bounds - a rectangle specifying the image's width and height (must not be null)

Image

public Image(Device device,
             ImageData data)
Enabled: Constructs an instance of this class from the given ImageData.

Parameters:
device - the device on which to create the image
data - the image data to create the image from (must not be null)

Image

public Image(Device device,
             ImageData source,
             ImageData mask)
Enabled: Constructs an instance of this class, whose type is SWT.ICON, from the two given ImageData objects. The two images must be the same size, and the mask image must have a color depth of 1. Pixel transparency in either image will be ignored. If either image is an icon to begin with, an exception is thrown.

The mask image should contain white wherever the icon is to be visible, and black wherever the icon is to be transparent. In addition, the source image should contain black wherever the icon is to be transparent.

Parameters:
device - the device on which to create the icon
source - the color data for the icon
mask - the mask data for the icon

Image

public Image(Device device,
             InputStream stream)
Enabled: 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.

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:

     new Image(device, clazz.getResourceAsStream("file.gif"));
 

Parameters:
device - the device on which to create the image
stream - the input stream to load the image from

Image

public Image(Device device,
             String filename)
Suppressed: 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
filename - the name of the file to load the image from
Method Detail

createDIBFromDDB

int createDIBFromDDB(int hDC,
                     int hBitmap,
                     int width,
                     int height)
Create a DIB from a DDB without using GetDIBits. Note that the DDB should not be selected into a HDC.


dispose

public void dispose()
Enabled: Disposes of the operating system resources associated with the image. Applications must dispose of all images which they allocate.


equals

public boolean equals(Object object)
Suppressed: Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the object is the same as this object and false otherwise
See Also:
hashCode()

getBackground

public Color getBackground()
Enabled: Returns the color to which to map the transparent pixel, or null if the receiver has no transparent pixel.

There are certain uses of Images that do not support transparency (for example, setting an image into a button or label). In these cases, it may be desired to simulate transparency by using the background color of the widget to paint the transparent pixels of the image. Use this method to check which color will be used in these cases in place of transparency. This value may be set with setBackground().

Returns:
the background color of the image, or null if there is no transparency in the image

getBounds

public Rectangle getBounds()
Enabled: 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

getImageData

public ImageData getImageData()
Enabled: Returns an ImageData based on the receiver Modifications made to this ImageData will not affect the Image.

Returns:
an ImageData containing the image's data and attributes
See Also:
ImageData

hashCode

public int hashCode()
Suppressed: Returns an integer hash code for the receiver. Any two objects which return true when passed to equals must return the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

init

void init(Device device,
          int width,
          int height)

GetIconInfo

static void GetIconInfo(Image image,
                        org.eclipse.swt.internal.win32.ICONINFO info)
Feature in WinCE. GetIconInfo is not available in WinCE. The workaround is to cache the object ImageData for images of type SWT.ICON. The bitmaps hbmMask and hbmColor can then be reconstructed by using our version of getIconInfo. This function takes an ICONINFO object and sets the fields hbmMask and hbmColor with the corresponding bitmaps it has created. Note. These bitmaps must be freed - as they would have to be if the regular GetIconInfo had been used.


init

static int[] init(Device device,
                  Image image,
                  ImageData i)

init

void init(Device device,
          ImageData i)

internal_new_GC

public int internal_new_GC(GCData data)
Suppressed: Invokes platform specific functionality to allocate a new GC handle.

IMPORTANT: This method is not part of the public API for Image. 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 called from application code.

Specified by:
internal_new_GC in interface Drawable
Parameters:
data - the platform specific GC data
Returns:
the platform specific GC handle

internal_dispose_GC

public void internal_dispose_GC(int hDC,
                                GCData data)
Suppressed: Invokes platform specific functionality to dispose a GC handle.

IMPORTANT: This method is not part of the public API for Image. 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 called from application code.

Specified by:
internal_dispose_GC in interface Drawable
Parameters:
data - the platform specific GC data
hDC - the platform specific GC handle

isDisposed

public boolean isDisposed()
Enabled: Returns true if the image has been disposed, and false otherwise.

This method gets 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

setBackground

public void setBackground(Color color)
Enabled: Sets the color to which to map the transparent pixel.

There are certain uses of Images that do not support transparency (for example, setting an image into a button or label). In these cases, it may be desired to simulate transparency by using the background color of the widget to paint the transparent pixels of the image. This method specifies the color that will be used in these cases. For example:

    Button b = new Button();
    image.setBackground(b.getBackground());>
    b.setImage(image);
 

The image may be modified by this operation (in effect, the transparent regions may be filled with the supplied color). Hence this operation is not reversible and it is not legal to call this function twice or with a null argument.

This method has no effect if the receiver does not have a transparent pixel value.

Parameters:
color - the color to use when a transparent pixel is specified

toString

public String toString()
Suppressed: Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
a string representation of the receiver

win32_new

public static Image win32_new(Device device,
                              int type,
                              int handle)
Suppressed: Invokes platform specific functionality to allocate a new image.

IMPORTANT: This method is not part of the public API for Image. 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 called from application code.

Parameters:
device - the device on which to allocate the color
type - the type of the image (SWT.BITMAP or SWT.ICON)
handle - the OS handle for the image


comments?