|
Eclipse Rich Ajax Platform Release 1.3 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.graphics.Resource
org.eclipse.swt.graphics.Image
Instances of this class are graphics which have been prepared
for display on a specific device. That is, they are to 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.
Note: Even though constructors are provided here, it is
recommended to create images by using one of the getImage
methods in class Graphics
. These factory methods share images
among all sessions.
Creating images via constructors carelessly may lead to bad performance
and/or unnecessary memory consumption.
Graphics.getImage(String)
,
Graphics.getImage(String, ClassLoader)
,
Graphics.getImage(String, java.io.InputStream)
Field Summary | |
String |
resourceName
IMPORTANT: This field is not part of the SWT public API. |
Constructor Summary | |
Image(Device device,
ImageData imageData)
Constructs an instance of this class from the given ImageData . |
|
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,
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. |
Method Summary | |
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. |
Methods inherited from class org.eclipse.swt.graphics.Resource |
dispose, getDevice, isDisposed |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public String resourceName
Constructor Detail |
public Image(Device device, InputStream 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; }
Note, this constructor is provided for convenience when
single-sourcing code with SWT. For RWT, the recommended way to create images
is to use one of the Graphics#getImage()
methods.
device
- the device on which to create the imagestream
- the input stream to load the image from
IllegalArgumentException
- SWTException
- SWTError
- Graphics.getImage(String)
,
Graphics.getImage(String, ClassLoader)
,
Graphics.getImage(String, java.io.InputStream)
public Image(Device device, String fileName)
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.
Note, this constructor is provided for convenience when
single-sourcing code with SWT. For RWT, the recommended way to create images
is to use one of the Graphics#getImage()
methods.
device
- the device on which to create the image
IllegalArgumentException
- SWTException
- SWTError
- Graphics.getImage(String)
,
Graphics.getImage(String, ClassLoader)
,
Graphics.getImage(String, java.io.InputStream)
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
IllegalArgumentException
- IMAGE_COPY
, IMAGE_DISABLE
or IMAGE_GRAY
SWTException
- SWTError
- public Image(Device device, ImageData imageData)
ImageData
.
device
- the device on which to create the image
IllegalArgumentException
- SWTException
- Method Detail |
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 attributes
SWTException
- 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 specified
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
-
|
Eclipse Rich Ajax Platform Release 1.3 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2009. All rights reserved.