MID Profile

javax.microedition.lcdui
Class Image

java.lang.Object
  |
  +--javax.microedition.lcdui.Image

public class Image
extends Object

The Image class is used to used to hold graphical image data. Image objects exist independently of the display device. They exist only in off-screen memory and will not be painted on the display unless an explicit command is issued by the application (such as within the paint() method of a Canvas) or when an Image object is placed within a Form screen or an Alert screen and that screen is made current.

Images are either mutable or immutable depending upon how they are created. Immutable images are generally created by loading image data from resource bundles, from files, or from the network. They may not be modified once created. Mutable images are created in off-screen memory. The application may paint into them after having created a Graphics object expressly for this purpose. Images to be placed within an ImageItem or onto Form or Alert screens must be immutable. An immutable image may be created from a mutable image through the use of the createImage method. It is possible to create a mutable copy of an immutable image using a technique similar to the following:

	Image source; // the image to be copied
	Image copy = Image.createImage(source.getWidth(), source.getHeight());
	Graphics g = copy.getGraphics();
	g.drawImage(source, 0, 0, TOP|LEFT);
 

The implementations are assumed to support PNG as the image format. Implementation of filtering, progressive drawing/interlacing and transparency is not, however, required.


Method Summary
static Image createImage(byte[] imagedata, int imageoffset, int imagelength)
          Creates an immutable image which is decoded from the data stored in the specified byte array at the specified offset and length.
static Image createImage(Image image)
          Creates an immutable image from a mutable image.
static Image createImage(int width, int height)
          Creates a new, mutable image for off-screen drawing.
static Image createImage(String name)
          Creates an immutable image from decoded image data obtained from the named resource.
 Graphics getGraphics()
          Creates a Graphics object that renders to this image.
 int getHeight()
          Gets the height of the image in pixels.
 int getWidth()
          Gets the width of the image in pixels.
 boolean isMutable()
          Check if this image is mutable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createImage

public static Image createImage(int width,
                                int height)
Creates a new, mutable image for off-screen drawing. Every pixel within the newly created image is white.
Parameters:
width - the width, in pixels, of the new image
height - the height, in pixels, of the new image
Returns:
the created image
Throws:
IllegalArgumentException - if width <= 0 or height <= 0.

createImage

public static Image createImage(Image image)
Creates an immutable image from a mutable image. If the image is mutable, it is copied. This can be used in Alerts, Forms and Choices.
Parameters:
image - the image to be copied
Returns:
the created image

createImage

public static Image createImage(String name)
                         throws IOException
Creates an immutable image from decoded image data obtained from the named resource.
Parameters:
name - the name of the resource containing the pixel data in one of the recognized file formats.
Returns:
the created image
Throws:
IOException - if the resource does not exist, the data cannot be loaded, or the image data cannot be decoded

createImage

public static Image createImage(byte[] imagedata,
                                int imageoffset,
                                int imagelength)
Creates an immutable image which is decoded from the data stored in the specified byte array at the specified offset and length. The data must be in some image format supported by the implementation (such as PNG).

The imageoffset and imagelength parameters specify a range of data the imagedata byte array. The imageoffset parameter specifies the offset within the array of the first data byte to be used. It must therefore lie within the range [0..(imagedata.length-1)]. The imagelength parameter specifies the number of data bytes to be used. It must be a positive integer and it must not cause the range to extend beyond the end of the array. That is, it must be true that imageoffset + imagelength <= imagedata.length.

Images created by this method are immutable. Therefore, resources permitting, the implementation is allowed to provide a caching scheme and return the same image object if the same data is provided to a subsequent createImage() call. Similarly, the application can safely cache and reuse these images.

This method is intended for use when loading an image from ROM or from the network.

Parameters:
imagedata - the array of image data in a supported image format
imageoffset - the offset of the start of the data in the array
imagelength - the length of the data in the array
Returns:
the created image
Throws:
ArrayIndexOutOfBoundsException - if imageoffset and imagelength specify an invalid range
IllegalArgumentException - if imagedata is malformatted or otherwise cannot be decoded

getGraphics

public Graphics getGraphics()
Creates a Graphics object that renders to this image. This image must be mutable; it is illegal to call this method on an immutable image. The mutability of an image may be tested with the isMutable() method.
Returns:
a Graphics object with this image as its destination
Throws:
IllegalStateException - if the image is immutable

getWidth

public int getWidth()
Gets the width of the image in pixels.
Returns:
width of the image

getHeight

public int getHeight()
Gets the height of the image in pixels.
Returns:
height of the image

isMutable

public boolean isMutable()
Check if this image is mutable. Mutable images can be modified by rendering to them through a Graphics object obtained from the getGraphics() method of this object.
Returns:
true if the image is mutable, false otherwise

MID Profile

Submit a comment or suggestion Version 0.9 of MID Profile Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries. Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,Palo Alto, California, 94303, U.S.A. All Rights Reserved.