public class Image
extends java.lang.Object
Image
object holds graphical display data. Image
is either mutable or immutable depending on the way it has been created.OutOfMemoryError
is thrown.getGraphicsContext()
on the image to obtain a GraphicsContext
object expressly for
this purpose.Modifier and Type | Class and Description |
---|---|
static class |
Image.OutputFormat
Specify the format to apply when creating an immutable image.
|
Modifier and Type | Method and Description |
---|---|
static Image |
createImage(Display d,
int width,
int height)
Creates a new mutable image which respects the pixel organization (layout, bpp etc.) of the given display and
with the given size.
|
static Image |
createImage(Image image,
int x,
int y,
int width,
int height)
Creates an immutable image from another image area.
|
static Image |
createImage(Image image,
int x,
int y,
int width,
int height,
Image.OutputFormat format)
Creates an immutable image from another image area.
|
static Image |
createImage(java.io.InputStream stream,
int size)
Creates an immutable image from an
InputStream .The resource image format (input format) is a standard image format ( PNG etc.) According the MicroUI
implementation the image can be loaded or not. |
static Image |
createImage(java.io.InputStream stream,
int size,
Image.OutputFormat format)
Creates an immutable image from an
InputStream .The resource image format (input format) is a standard image format ( PNG etc.) According the
MicroUI implementation the image can be loaded or not. |
static Image |
createImage(int width,
int height)
Creates a new mutable image which respects the pixel organization (layout, bpp etc.) of the default display and
with the given size.
|
static Image |
createImage(java.lang.String name)
Creates an immutable image from a resource.
The resource image format (input format) is a standard image format ( PNG etc.) or an internal
MicroUI implementation specific format. |
static Image |
createImage(java.lang.String name,
Image.OutputFormat format)
Creates an immutable image from a resource.
The resource image format (input format) is a standard image format ( PNG etc.) or an internal
MicroUI implementation specific format. |
void |
getARGB(int[] argbData,
int offset,
int scanlength,
int x,
int y,
int width,
int height)
Obtains ARGB pixel data from the specified region of this image and stores it in the provided array of integers.
|
GraphicsContext |
getGraphicsContext()
Returns a new
GraphicsContext object to draw on the image. |
int |
getHeight()
Returns the height of the image in pixels.
|
int |
getWidth()
Returns the width of the image in pixels.
|
boolean |
isMutable()
Tells whether this image is mutable.
|
boolean |
isTransparent()
Tells whether this image contains at least a transparent pixel.
|
int |
readPixel(int x,
int y)
Obtains the ARGB color of the pixel at
(x,y) . |
public static Image createImage(int width, int height)
width
and
height
must be greater than zero.The effect is identical tocreateImage(Display.getDefaultDisplay(), width, height);
width
- the width of the new image, in pixels.height
- the height of the new image, in pixels.java.lang.IllegalArgumentException
- if either width
or height
is zero or less.ImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.IllegalStateException
- if MicroUI is not started.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.createImage(Display, int, int)
public static Image createImage(Display d, int width, int height)
width
and
height
must be greater than zero.d
- the display for which the image is created.width
- the width of the new image, in pixels.height
- the height of the new image, in pixels.java.lang.IllegalArgumentException
- if either width
or height
is zero or lessImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.public static Image createImage(java.lang.String name) throws java.io.IOException
PNG
etc.) or an internal
MicroUI implementation specific format. According the MicroUI implementation the image can be loaded or not. For
instance, when MicroUI implementation does not hold a dynamic PNG
decoder, load a PNG
is impossible. IOException
is thrown. PNG
image output format
is Image.OutputFormat.ARGB8888
(32 bits per pixels with 256 levels of transparency). createImage(name, null);
name
- a resource name matching image data in a supported image format.java.lang.NullPointerException
- if name is null
.java.io.IOException
- if the resource is not found, if the data can not be decoded or if the name is not an absolute path.ImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.java.lang.IllegalStateException
- if MicroUI is not started.createImage(String, OutputFormat)
public static Image createImage(java.lang.String name, Image.OutputFormat format) throws java.io.IOException
PNG
etc.) or an internal
MicroUI implementation specific format. According the MicroUI implementation the image can be loaded or not. For
instance, when MicroUI implementation does not hold a dynamic PNG
decoder, load a PNG
is impossible. IOException
is thrown. createImage(String)
.name
- a resource name matching image data in a supported image format.format
- the expected output format or null
to use the best output format according the input
image format.java.lang.NullPointerException
- if name is null
.java.io.IOException
- if the resource is not found, if the data can not be decoded or if the name is not an absolute path.ImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.java.lang.IllegalStateException
- if MicroUI is not started.public static Image createImage(Image image, int x, int y, int width, int height)
(x,y)
relative to the
image and a size (width,height)
.image
may be returned. createImage(image, x, y, width, height, null);
image
- the source image.x
- the x coordinate of the area to copy.y
- the y coordinate of the area to copy.width
- the width of the area to copy.height
- the height of the area to copy.java.lang.NullPointerException
- if image is null
.java.lang.IllegalArgumentException
- if the area to copy is out of the bounds of the source image or if either width
or
height
is zero or negative.ImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.createImage(Image, int, int, int, int, OutputFormat)
public static Image createImage(Image image, int x, int y, int width, int height, Image.OutputFormat format)
(x,y)
relative to the
image and a size (width,height)
.image
may be returned.image
- the source image.x
- the x coordinate of the area to copy.y
- the y coordinate of the area to copy.width
- the width of the area to copy.height
- the height of the area to copy.format
- the expected output format or null
to use the source image format.java.lang.NullPointerException
- if image is null
.java.lang.IllegalArgumentException
- if the area to copy is out of the bounds of the source image or if either width
or
height
is zero or negative.ImageCreationException
- if MicroUI implementation cannot create the imagejava.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.public static Image createImage(java.io.InputStream stream, int size) throws java.io.IOException
InputStream
.PNG
etc.) According the MicroUI
implementation the image can be loaded or not. For instance, when MicroUI implementation does not hold a dynamic
PNG
decoder, load a PNG
is impossible. IOException
is thrown. PNG
image output format
is Image.OutputFormat.ARGB8888
(32 bits per pixels with 256 levels of transparency). createImage(stream, size, format);
stream
- a stream providing image data.size
- the number of bytes to read.java.lang.NullPointerException
- if stream is null
.java.io.IOException
- if the resource is not found, if the data can not be decoded or if the stream cannot be read.ImageCreationException
- if MicroUI implementation cannot create the image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.java.lang.IllegalStateException
- if MicroUI is not started.createImage(InputStream, int, OutputFormat)
public static Image createImage(java.io.InputStream stream, int size, Image.OutputFormat format) throws java.io.IOException
InputStream
.PNG
etc.) According the
MicroUI implementation the image can be loaded or not. For instance, when MicroUI implementation does not hold a
dynamic PNG
decoder, load a PNG
is impossible. IOException
is thrown. createImage(InputStream, int)
.stream
- a stream providing image datasize
- the number of bytes to readformat
- the expected output format or null to use the best output format according the input image formatjava.lang.NullPointerException
- if stream is nulljava.io.IOException
- if the resource is not found, if the data can not be decoded or if the stream cannot be read.ImageCreationException
- if MicroUI implementation cannot create the imagejava.lang.SecurityException
- if a security manager exists and does not allow the caller to create an image.java.lang.OutOfMemoryError
- if there is not enough room to add a new image.java.lang.IllegalStateException
- if MicroUI is not started.public GraphicsContext getGraphicsContext()
GraphicsContext
object to draw on the image. The image must be mutable, otherwise an
IllegalArgumentException
is thrown. The returned GraphicsContext
object has the default
GraphicsContext
behavior and allows the entire image to be drawn.GraphicsContext
object which maps this imagejava.lang.IllegalArgumentException
- if the image is immutablepublic int getWidth()
public int getHeight()
public boolean isMutable()
public boolean isTransparent()
public int readPixel(int x, int y)
(x,y)
. The read color may be different than the drawing
color. It is screen dependent, according to the number of bits per pixels (see Display.getBPP()
).x
- the x coordinate of the pixely
- the y coordinate of the pixeljava.lang.IllegalArgumentException
- if the pixel coordinates are out of bounds of the source graphics contextpublic void getARGB(int[] argbData, int offset, int scanlength, int x, int y, int width, int height)
The returned values are not guaranteed to be identical to values from the original source, such as from
createRGBImage or from a PNG image. Color values may be resampled to reflect the display capabilities of the
device (for example, red, green or blue pixels may all be represented by the same gray value on a grayscale
device). On devices that do not support alpha blending, the alpha value will be 0xFF for opaque pixels and 0x00
for all other pixels. On devices that support alpha blending, alpha channel values may be resampled to reflect
the number of levels of semitransparency supported.
The scanlength specifies the relative offset within the array between the corresponding pixels of consecutive
rows. In order to prevent rows of stored pixels from overlapping, the absolute value of scanlength must be
greater than or equal to width. Negative values of scanlength are allowed. In all cases, this must result in
every reference being within the bounds of the rgbData array.
argbData
- an array of integers in which the ARGB pixel data is storedoffset
- the index into the array where the first ARGB value is storedscanlength
- the relative offset in the array between corresponding pixels in consecutive rows of the regionx
- the x-coordinate of the upper left corner of the regiony
- the y-coordinate of the upper left corner of the regionwidth
- the width of the regionheight
- the height of the regionjava.lang.ArrayIndexOutOfBoundsException
- if the requested operation would attempt to access an element in the rgbData array whose index is
either negative or beyond its length (the contents of the array are unchanged)java.lang.IllegalArgumentException
- if the area being retrieved exceeds the bounds of the source imagejava.lang.IllegalArgumentException
- if the absolute value of scanlength is less than widthjava.lang.NullPointerException
- - if argbData is null