public class Image extends Resource implements 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.
Modifier and Type | Field and Description |
---|---|
InternalImage |
internalImage
The internal resource.
|
Constructor and Description |
---|
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,
int width,
int height)
Constructs an empty instance of this class with the
specified width and height.
|
Modifier and Type | Method and Description |
---|---|
Color |
getBackground()
Returns the color to which to map the transparent pixel, or null if
the receiver has no transparent pixel.
|
Rectangle |
getBounds()
Returns the bounds of the receiver.
|
ImageData |
getImageData()
Returns an
ImageData based on the receiver
Modifications made to this ImageData will not
affect the Image. |
void |
setBackground(Color color)
Sets the color to which to map the transparent pixel.
|
dispose, getDevice, isDisposed
public final InternalImage internalImage
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.
public Image(Device device, Image srcImage, int flag)
SWT.IMAGE_COPY
SWT.IMAGE_DISABLE
SWT.IMAGE_GRAY
device
- the device on which to create the imagesrcImage
- the image to use as the sourceflag
- the style, either IMAGE_COPY
, IMAGE_DISABLE
or IMAGE_GRAY
java.lang.IllegalArgumentException
- IMAGE_COPY
, IMAGE_DISABLE
or IMAGE_GRAY
SWTException
- SWTError
- public Image(Device device, int width, int height)
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.
device
- the device on which to create the imagewidth
- the width of the new imageheight
- the height of the new imagejava.lang.IllegalArgumentException
- SWTError
- public Rectangle getBounds()
SWTException
- public ImageData getImageData()
ImageData
based on the receiver
Modifications made to this ImageData
will not
affect the Image.ImageData
containing the image's data and attributesSWTException
- ImageData
public void setBackground(Color color)
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.
color
- the color to use when a transparent pixel is specifiedjava.lang.IllegalArgumentException
- SWTException
- public Color getBackground()
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().
SWTException
-
Copyright (c) EclipseSource and others 2002, 2020.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0