Class Image
- All Implemented Interfaces:
Drawable
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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs an empty instance of this class with the specified width and height.Constructs a new instance of this class based on the provided image, with an appearance that varies depending on the value of the flag. -
Method Summary
Modifier and TypeMethodDescriptionReturns the color to which to map the transparent pixel, or null if the receiver has no transparent pixel.Returns the bounds of the receiver.Returns anImageData
based on the receiver Modifications made to thisImageData
will not affect the Image.void
setBackground
(Color color) Sets the color to which to map the transparent pixel.Methods inherited from class org.eclipse.swt.graphics.Resource
dispose, getDevice, isDisposed
-
Field Details
-
internalImage
public final InternalImage internalImageThe internal 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.
-
-
Constructor Details
-
Image
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
- Parameters:
device
- the device on which to create the imagesrcImage
- the image to use as the sourceflag
- the style, eitherIMAGE_COPY
,IMAGE_DISABLE
orIMAGE_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
orIMAGE_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
- Since:
- 1.3
-
Image
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 imagewidth
- the width of the new imageheight
- 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
- Since:
- 1.4
-
-
Method Details
-
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_GRAPHIC_DISPOSED - if the receiver has been disposed
- ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon
-
getImageData
Returns anImageData
based on the receiver Modifications made to thisImageData
will not affect the Image.- Returns:
- an
ImageData
containing the image's data and attributes - 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:
- 1.3
- See Also:
-
setBackground
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
- Since:
- 1.3
-
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
- Since:
- 1.3
-