Class Image

java.lang.Object
org.eclipse.swt.graphics.Resource
org.eclipse.swt.graphics.Image
All Implemented Interfaces:
Drawable

public final class Image extends Resource implements Drawable
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 explicitly invoke the Image.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private int
    Attribute to cache current device zoom level
    (package private) static final int
    Specifies the default scanline padding.
    (package private) int
    The height of the image.
    ImageDataProvider to provide ImageData at various Zoom levels
    ImageFileNameProvider to provide file names at various Zoom levels
    ImageGcDrawer to provide a callback to draw on a GC for various zoom levels
    long
    The handle to the OS mask resource.
    (package private) GC
    The GC the image is currently selected in.
    private int
    Style flag used to differentiate normal, gray-scale and disabled images based on image data providers.
    long
    The handle to the OS cairo surface resource.
    (package private) int
    specifies the transparent pixel
    int
    specifies whether the receiver is a bitmap or an icon (one of SWT.BITMAP, SWT.ICON)
    (package private) int
    The width of the image.

    Fields inherited from class Resource

    device
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    (package private)
    Image(Device device)
     
     
    Image(Device device, int width, int height)
    Constructs an empty instance of this class with the specified width and height.
     
    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.
     
    Image(Device device, ImageData data)
    Constructs an instance of this class from the given ImageData.
    private
    Image(Device device, ImageData data, int zoom)
     
     
    Image(Device device, ImageDataProvider imageDataProvider)
    Constructs an instance of this class by loading its representation from the ImageData retrieved from the ImageDataProvider.
     
    Image(Device device, ImageData source, ImageData mask)
    Constructs an instance of this class, whose type is SWT.ICON, from the two given ImageData objects.
     
    Image(Device device, ImageFileNameProvider imageFileNameProvider)
    Constructs an instance of this class by loading its representation from the file retrieved from the ImageFileNameProvider.
     
    Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
    The provided ImageGcDrawer will be called on demand whenever a new variant of the Image for an additional zoom is required.
     
    Image(Device device, Image srcImage, int flag)
    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, Rectangle bounds)
    Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    createFromPixbuf(int type, long pixbuf)
     
    (package private) void
    Create the receiver's mask if necessary.
    (package private) void
     
    (package private) void
    Destroy the receiver's mask if it exists.
    static void
    drawAtSize(GC gc, ImageData imageData, int width, int height)
    IMPORTANT: This method is not part of the public API for Image.
    private ImageData
    drawWithImageGcDrawer(int width, int height, int zoom)
     
    boolean
    equals(Object object)
    Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
    (package private) void
    executeOnImageAtSize(Consumer<Image> imageAtBestFittingSizeConsumer, int destWidth, int destHeight)
     
    Returns the color to which to map the transparent pixel, or null if the receiver has no transparent pixel.
    Returns the bounds of the receiver.
    Deprecated, for removal: This API element is subject to removal in a future version.
    This API doesn't serve the purpose in an environment having multiple monitors with different DPIs, hence deprecated.
    Returns an ImageData based on the receiver.
    getImageData(int zoom)
    Returns an ImageData for the given zoom level based on the receiver.
    Deprecated, for removal: This API element is subject to removal in a future version.
    This API doesn't serve the purpose in an environment having multiple monitors with different DPIs, hence deprecated.
    static Image
    gtk_new(Device device, int type, long imageHandle, long mask)
    Invokes platform specific functionality to allocate a new image.
    static Image
    gtk_new_from_pixbuf(Device device, int type, long pixbuf)
    Invokes platform specific functionality to allocate a new image.
    int
    Returns an integer hash code for the receiver.
    (package private) void
    init(int width, int height)
     
    (package private) void
    init(ImageData image)
     
    private void
    init(ImageData image, int zoom)
     
    private void
     
    private void
     
    (package private) void
    initNative(String filename)
     
    void
    internal_dispose_GC(long hDC, GCData data)
    Invokes platform specific functionality to dispose a GC handle.
    boolean
    Refreshes the image for the current device scale factor.
    long
    Invokes platform specific functionality to allocate a new GC handle.
    boolean
    Returns true if the image has been disposed, and false otherwise.
    (package private) boolean
    Refresh the Image based on the zoom level, if required.
    void
    Sets the color to which to map the transparent pixel.
    Returns a string containing a concise, human-readable description of the receiver.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Drawable

    isAutoScalable
  • Field Details

    • type

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

      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.

    • mask

      public long mask
      The handle to the OS mask resource. (Warning: This field is platform dependent)

      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.

    • surface

      public long surface
      The handle to the OS cairo surface resource. (Warning: This field is platform dependent)

      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.

    • transparentPixel

      int transparentPixel
      specifies the transparent pixel
    • memGC

      GC memGC
      The GC the image is currently selected in.
    • width

      int width
      The width of the image.
    • height

      int height
      The height of the image.
    • DEFAULT_SCANLINE_PAD

      static final int DEFAULT_SCANLINE_PAD
      Specifies the default scanline padding.
      See Also:
    • imageFileNameProvider

      private ImageFileNameProvider imageFileNameProvider
      ImageFileNameProvider to provide file names at various Zoom levels
    • imageDataProvider

      private ImageDataProvider imageDataProvider
      ImageDataProvider to provide ImageData at various Zoom levels
    • imageGcDrawer

      private ImageGcDrawer imageGcDrawer
      ImageGcDrawer to provide a callback to draw on a GC for various zoom levels
    • styleFlag

      private int styleFlag
      Style flag used to differentiate normal, gray-scale and disabled images based on image data providers. Without this, a normal and a disabled image of the same image data provider would be considered equal.
    • currentDeviceZoom

      private int currentDeviceZoom
      Attribute to cache current device zoom level
    • cachedImageAtSize

      private Image.CachedImageAtSize cachedImageAtSize
  • Constructor Details

    • Image

      Image(Device device)
    • Image

      public Image(Device device, int width, int height)
      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.

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the image
      width - the width of the new image
      height - the height of the new image
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • Image

      public Image(Device device, Image srcImage, int flag)
      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:
      SWT.IMAGE_COPY
      the result is an identical copy of srcImage
      SWT.IMAGE_DISABLE
      the result is a copy of srcImage which has a disabled look
      SWT.IMAGE_GRAY
      the result is a copy of srcImage which has a gray scale look

      You must dispose the image when it is no longer required.

      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
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if srcImage is null
      • ERROR_INVALID_ARGUMENT - if the flag is not one of IMAGE_COPY, IMAGE_DISABLE or IMAGE_GRAY
      • ERROR_INVALID_ARGUMENT - if the image has been disposed
      SWTException -
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state
      • ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • Image

      @Deprecated(since="2025-06", forRemoval=true) public Image(Device device, Rectangle bounds)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the image
      bounds - a rectangle specifying the image's width and height (must not be null)
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if the bounds rectangle is null
      • ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • Image

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

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the image
      data - the image data to create the image from (must not be null)
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if the image data is null
      SWTException -
      • ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • Image

      private Image(Device device, ImageData data, int zoom)
    • Image

      public Image(Device device, ImageData source, ImageData mask)
      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. Pixel transparency in either image will be ignored.

      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.

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the icon
      source - the color data for the icon
      mask - the mask data for the icon
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if either the source or mask is null
      • ERROR_INVALID_ARGUMENT - if source and mask are different sizes
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • 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;
          }
      

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the image
      stream - the input stream to load the image from
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • 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_DEPTH - if the image stream describes an image with an unsupported depth
      • ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • 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.

      You must dispose the image when it is no longer required.

      Parameters:
      device - the device on which to create the image
      filename - the name of the file to load the image from
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • 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_DEPTH - if the image file describes an image with an unsupported depth
      • ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      See Also:
    • Image

      public Image(Device device, ImageFileNameProvider imageFileNameProvider)
      Constructs an instance of this class by loading its representation from the file retrieved from the ImageFileNameProvider. 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 for loading image as per DPI level.

      Parameters:
      device - the device on which to create the image
      imageFileNameProvider - the ImageFileNameProvider object that is to be used to get the file name
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if the ImageFileNameProvider is null
      • ERROR_INVALID_ARGUMENT - if the fileName provided by ImageFileNameProvider is null at 100% zoom
      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_DEPTH - if the image file describes an image with an unsupported depth
      • ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      Since:
      3.104
    • Image

      public Image(Device device, ImageDataProvider imageDataProvider)
      Constructs an instance of this class by loading its representation from the ImageData retrieved from the ImageDataProvider. 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 for loading image as per DPI level.

      Parameters:
      device - the device on which to create the image
      imageDataProvider - the ImageDataProvider object that is to be used to get the ImageData
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if the ImageDataProvider is null
      • ERROR_INVALID_ARGUMENT - if the ImageData provided by ImageDataProvider is null at 100% zoom
      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_DEPTH - if the image file describes an image with an unsupported depth
      • ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format
      SWTError -
      • ERROR_NO_HANDLES if a handle could not be obtained for image creation
      Since:
      3.104
    • Image

      public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
      The provided ImageGcDrawer will be called on demand whenever a new variant of the Image for an additional zoom is required. Depending on the OS-specific implementation these calls will be done during the instantiation or later when a new variant is requested.
      Parameters:
      device - the device on which to create the image
      imageGcDrawer - the ImageGcDrawer object to be called when a new image variant for another zoom is required.
      width - the width of the new image in points
      height - the height of the new image in points
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      • ERROR_NULL_ARGUMENT - if the ImageGcDrawer is null
      Since:
      3.129
  • Method Details

    • internal_gtk_refreshImageForZoom

      public boolean internal_gtk_refreshImageForZoom()
      Refreshes the image for the current device scale factor.

      IMPORTANT: This function 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 used from application code.

    • refreshImageForZoom

      boolean refreshImageForZoom()
      Refresh the Image based on the zoom level, if required.
      Returns:
      true if image is refreshed
    • initNative

      void initNative(String filename)
    • initFromFileNameProvider

      private void initFromFileNameProvider(int zoom)
    • initFromImageDataProvider

      private void initFromImageDataProvider(int zoom)
    • createFromPixbuf

      void createFromPixbuf(int type, long pixbuf)
    • createMask

      void createMask()
      Create the receiver's mask if necessary.
    • destroyMask

      void destroyMask()
      Destroy the receiver's mask if it exists.
    • destroy

      void destroy()
      Overrides:
      destroy in class Resource
    • executeOnImageAtSize

      void executeOnImageAtSize(Consumer<Image> imageAtBestFittingSizeConsumer, int destWidth, int destHeight)
    • equals

      public boolean equals(Object object)
      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:
    • getBackground

      public Color getBackground()
      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
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • 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 in points.
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
    • getBoundsInPixels

      @Deprecated(since="2025-09", forRemoval=true) public Rectangle getBoundsInPixels()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This API doesn't serve the purpose in an environment having multiple monitors with different DPIs, hence deprecated.
      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 in pixels.
      Returns:
      a rectangle specifying the image's bounds in pixels.
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
      Since:
      3.105
    • getImageData

      public ImageData getImageData()
      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 at 100% zoom level.
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
      See Also:
    • getImageDataAtCurrentZoom

      @Deprecated(since="2025-09", forRemoval=true) public ImageData getImageDataAtCurrentZoom()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This API doesn't serve the purpose in an environment having multiple monitors with different DPIs, hence deprecated. Use getImageData(int) instead.
      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 at the current zoom level.
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
      Since:
      3.105
      See Also:
    • getImageData

      public ImageData getImageData(int zoom)
      Returns an ImageData for the given zoom level based on the receiver.

      Note that this method is mainly intended to be used by custom implementations of ImageDataProvider that draw a composite image at the requested zoom level based on other images. For custom zoom levels, the image data may be an auto-scaled version of the native image and may look more blurred or mangled than expected.

      Modifications made to the returned ImageData will not affect this Image.

      Parameters:
      zoom - The zoom level in % of the standard resolution (which is 1 physical monitor pixel == 1 SWT logical point). Typically 100, 150, or 200.
      Returns:
      an ImageData containing the image's data and attributes at the given zoom level
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      • ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
      Since:
      3.106
    • drawWithImageGcDrawer

      private ImageData drawWithImageGcDrawer(int width, int height, int zoom)
    • gtk_new

      public static Image gtk_new(Device device, int type, long imageHandle, long mask)
      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)
      imageHandle - the OS handle for the image
      mask - the OS handle for the image mask
    • gtk_new_from_pixbuf

      public static Image gtk_new_from_pixbuf(Device device, int type, long pixbuf)
      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)
      pixbuf - an GdkPixbuf
    • hashCode

      public int hashCode()
      Returns an integer hash code for the receiver. Any two objects that 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:
    • init

      void init(int width, int height)
    • init

      void init(ImageData image)
    • init

      private void init(ImageData image, int zoom)
    • internal_new_GC

      public long internal_new_GC(GCData data)
      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(long hDC, GCData data)
      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:
      hDC - the platform specific GC handle
      data - the platform specific GC data
    • isDisposed

      public boolean isDisposed()
      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 (except Resource.dispose()) using the image.

      Specified by:
      isDisposed in class Resource
      Returns:
      true when the image is disposed and false otherwise
    • setBackground

      public void setBackground(Color color)
      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
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the color is null
      • ERROR_INVALID_ARGUMENT - if the color has been disposed
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • toString

      public String toString()
      Returns a string containing a concise, human-readable description of the receiver.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the receiver
    • drawAtSize

      public static void drawAtSize(GC gc, ImageData imageData, int width, int height)
      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. Draws a scaled image using the GC for a given imageData.
      Parameters:
      gc - the GC to draw on the resulting image
      imageData - the imageData which is used to draw the scaled Image
      width - the width to which the image is supposed to be scaled
      height - the height to which the image is supposed to be scaled