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.
Color, ImageData, ImageLoader, Image snippets, SWT Examples: GraphicsExample, ImageAnalyzer, Sample code and further information
| Modifier and Type | Field and Description |
|---|---|
| private int | currentDeviceZoom
Attribute to cache current device zoom level |
| pack-priv static final int | DEFAULT_SCANLINE_PAD
Specifies the default scanline padding. |
| pack-priv int | height
The height of the image. |
| private ImageDataProvider | imageDataProvider
ImageDataProvider to provide ImageData at various Zoom levels |
| private ImageFileNameProvider | imageFileNameProvider
ImageFileNameProvider to provide file names at various Zoom levels |
| public long | mask
The handle to the OS mask resource. |
| pack-priv GC | memGC
The GC the image is currently selected in. |
| private int | styleFlag
Style flag used to differentiate normal, gray-scale and disabled images based on image data providers. |
| public long | surface
The handle to the OS cairo surface resource. |
| pack-priv int | transparentPixel
specifies the transparent pixel |
| public int | type
specifies whether the receiver is a bitmap or an icon
(one of Important Note This field is not part of the SWT public API. |
| pack-priv int | width
The width of the image. |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| public | |
| public | Image(Device
the device on which to create the image device, Image the image to use as the source srcImage, int the style, either flag)IMAGE_COPY, IMAGE_DISABLE or IMAGE_GRAYConstructs a new instance of this class based on the provided image, with an appearance that varies depending on the value of the flag. |
| public | |
| public | |
| public | |
| public | Image(Device
the device on which to create the image device, InputStream the input stream to load the image from stream)Constructs an instance of this class by loading its representation from the specified input stream. |
| public | |
| public | Image(Device
the device on which to create the image device, ImageFileNameProvider the ImageFileNameProvider object that is
to be used to get the file name imageFileNameProvider)Constructs an instance of this class by loading its representation from the file retrieved from the ImageFileNameProvider. |
| public | Image(Device
the device on which to create the image device, ImageDataProvider the ImageDataProvider object that is
to be used to get the ImageData imageDataProvider)Constructs an instance of this class by loading its representation from the ImageData retrieved from the ImageDataProvider. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public boolean | Returns: true if the object is the same as this object and false otherwisethe object to compare with this object object)Overrides java. |
| public Color | Returns: the background color of the image, or null if there is no transparency in the imageReturns the color to which to map the transparent pixel, or null if the receiver has no transparent pixel. |
| public Rectangle | Returns: a rectangle specifying the image's bounds in points.Returns the bounds of the receiver. |
| public Rectangle | Returns: a rectangle specifying the image's bounds in pixels.
Deprecated
This API doesn't serve the purpose in an environment having
multiple monitors with different DPIs, hence deprecated.
Returns the bounds of the receiver.
|
| public ImageData | Returns: anImageData containing the image's data and
attributes at 100% zoom level.Returns an |
| public ImageData | Returns: anImageData containing the image's data and
attributes at the given zoom levelThe zoom level in % of the standard resolution (which is 1
physical monitor pixel == 1 SWT logical point). Typically 100,
150, or 200. zoom)Returns an |
| public ImageData | Returns: anImageData containing the image's data
and attributes at the current zoom level.
Deprecated
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.
|
| public static Image | |
| public static Image | gtk_new_from_pixbuf(Device
the device on which to allocate the color device, int the type of the image ( type, long SWT.BITMAP or SWT.ICON)an GdkPixbuf pixbuf)Invokes platform specific functionality to allocate a new image. |
| public int | Returns: the receiver's hashOverrides java. |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public void | internal_dispose_GC(long
the platform specific GC handle hDC, GCData the platform specific GC data data)Implements org. |
| public boolean | |
| public long | Returns: the platform specific GC handlethe platform specific GC data data)Implements org. |
| public boolean | Returns: true when the image is disposed and false otherwiseImplements abstract org. true if the image has been disposed,
and false otherwise.
|
| pack-priv boolean | Returns: true if image is refreshedRefresh the Image based on the zoom level, if required. |
| public void | setBackground(Color
the color to use when a transparent pixel is specified color)Sets the color to which to map the transparent pixel. |
| public String | Returns: a string representation of the receiverOverrides java. |
| currentDeviceZoom | back to summary |
|---|---|
| private int currentDeviceZoom Attribute to cache current device zoom level | |
| DEFAULT_SCANLINE_PAD | back to summary |
|---|---|
| pack-priv static final int DEFAULT_SCANLINE_PAD Specifies the default scanline padding. | |
| height | back to summary |
|---|---|
| pack-priv int height The height of the image. | |
| imageDataProvider | back to summary |
|---|---|
| private ImageDataProvider imageDataProvider ImageDataProvider to provide ImageData at various Zoom levels | |
| imageFileNameProvider | back to summary |
|---|---|
| private ImageFileNameProvider imageFileNameProvider ImageFileNameProvider to provide file names at various Zoom levels | |
| mask | back to summary |
|---|---|
| public long mask The handle to the OS mask resource. (Warning: This field is platform dependent) Important Note 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. | |
| memGC | back to summary |
|---|---|
| pack-priv GC memGC The GC the image is currently selected in. | |
| styleFlag | back to summary |
|---|---|
| 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. | |
| surface | back to summary |
|---|---|
| public long surface The handle to the OS cairo surface resource. (Warning: This field is platform dependent) Important Note 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 | back to summary |
|---|---|
| pack-priv int transparentPixel specifies the transparent pixel | |
| type | back to summary |
|---|---|
| public int type specifies whether the receiver is a bitmap or an icon
(one of Important Note 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. | |
| width | back to summary |
|---|---|
| pack-priv int width The width of the image. | |
| Image | back to summary |
|---|---|
| pack-priv Image(Device device) | |
| Image | back to summary |
|---|---|
| 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.
| |
| Image | back to summary |
|---|---|
| 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:
You must dispose the image when it is no longer required.
| |
| Image | back to summary |
|---|---|
| public Image(Device device, Rectangle bounds) 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.
| |
| Image | back to summary |
|---|---|
| public Image(Device device, ImageData data) Constructs an instance of this class from the given
You must dispose the image when it is no longer required.
| |
| Image | back to summary |
|---|---|
| public Image(Device device, ImageData source, ImageData mask) Constructs an instance of this class, whose type is
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.
| |
| Image | back to summary |
|---|---|
| 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
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.
| |
| Image | back to summary |
|---|---|
| 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.
| |
| Image | back to summary |
|---|---|
| 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.
| |
| Image | back to summary |
|---|---|
| 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.
| |
| createFromPixbuf | back to summary |
|---|---|
| pack-priv void createFromPixbuf(int type, long pixbuf) | |
| createMask | back to summary |
|---|---|
| pack-priv void createMask() Create the receiver's mask if necessary. | |
| createSurface | back to summary |
|---|---|
| pack-priv void createSurface() | |
| destroy | back to summary |
|---|---|
| pack-priv void destroy() Overrides org.
| |
| destroyMask | back to summary |
|---|---|
| pack-priv void destroyMask() Destroy the receiver's mask if it exists. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison. | |
| getBackground | back to summary |
|---|---|
| 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().
| |
| getBounds | back to summary |
|---|---|
| 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.
| |
| getBoundsInPixels | back to summary |
|---|---|
| public Rectangle getBoundsInPixels()
Deprecated 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.
| |
| getImageData | back to summary |
|---|---|
| public ImageData getImageData() Returns an
| |
| getImageData | back to summary |
|---|---|
| public ImageData getImageData(int zoom) Returns an
Note that this method is mainly intended to be used by custom
implementations of
Modifications made to the returned
| |
| getImageDataAtCurrentZoom | back to summary |
|---|---|
| public ImageData getImageDataAtCurrentZoom()
Deprecated This API doesn't serve the purpose in an environment having
multiple monitors with different DPIs, hence deprecated. Use
Returns an
| |
| gtk_new | back to summary |
|---|---|
| public static Image gtk_new(Device device, int type, long imageHandle, long mask) Invokes platform specific functionality to allocate a new image. Important Note This method is not part of the public
API for
| |
| gtk_new_from_pixbuf | back to summary |
|---|---|
| public static Image gtk_new_from_pixbuf(Device device, int type, long pixbuf) Invokes platform specific functionality to allocate a new image. Important Note This method is not part of the public
API for
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns an integer hash code for the receiver. Any two
objects that return | |
| init | back to summary |
|---|---|
| pack-priv void init(int width, int height) | |
| init | back to summary |
|---|---|
| pack-priv void init(ImageData image) | |
| initNative | back to summary |
|---|---|
| pack-priv void initNative(String filename) | |
| internal_dispose_GC | back to summary |
|---|---|
| public void internal_dispose_GC(long hDC, GCData data) Implements org. Invokes platform specific functionality to dispose a GC handle. Important Note This method is not part of the public
API for | |
| internal_gtk_refreshImageForZoom | back to summary |
|---|---|
| public boolean internal_gtk_refreshImageForZoom() Refreshes the image for the current device scale factor. Important Note 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. | |
| internal_new_GC | back to summary |
|---|---|
| public long internal_new_GC(GCData data) Implements org. Invokes platform specific functionality to allocate a new GC handle. Important Note This method is not part of the public
API for | |
| isDisposed | back to summary |
|---|---|
| public boolean isDisposed() Implements abstract org. Returns
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
| |
| refreshImageForZoom | back to summary |
|---|---|
| pack-priv boolean refreshImageForZoom() Refresh the Image based on the zoom level, if required.
| |
| setBackground | back to summary |
|---|---|
| public void setBackground(Color color) Sets the color to which to map the transparent pixel.
There are certain uses of 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.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string containing a concise, human-readable description of the receiver. | |