Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| MID Profile
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.microedition.lcdui
Class Image

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

public class Image
extends Object

The Image class is 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 Alert, Choice, Form, or ImageItem objects are required to be immutable because the implementation may use them to update the display at any time, without notifying the application.

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
        source = Image.createImage(...);
        Image copy = Image.createImage(source.getWidth(), source.getHeight());
        Graphics g = copy.getGraphics();
        g.drawImage(source, 0, 0, TOP|LEFT);

It is also possible to use this technique to create a copy of a subrectangle of an image, by altering the width and height parameters of the createImage() call that creates the destination image and by altering the x and y parameters of the drawImage() call.

### PNG Image Format

Implementations are required to support images stored in the Portable Network Graphics (PNG) format. All of the 'critical' chunks specified by PNG must be supported, with the following considerations.

The IHDR chunk. MIDP devices must handle the following values in the IHDR chunk:

- All positive values of width and height are supported; however, a very large image may not be readable because of memory constraints.
- All color types are supported, although the appearance of the image will be dependent on the capabilities of the device's screen. Color types that include alpha channel data are supported; however, the implementation may ignore all alpha channel information and treat all pixels as opaque.
- All bit depth values for the given color type are supported.
- Compression method 0 (deflate) is the only supported compression method. This is the same compression method that is used for jar files, and so the decompression (inflate) code may be shared between the jar decoding and PNG decoding implementations.
- The filter method represents a series of encoding schemes that may be used to optimize compression. The PNG spec currently defines a single filter method (method 0) that is an adaptive filtering scheme with five basic filter types. Filtering is essential for optimal compression since it allows the deflate algorithm to exploit spatial similarities within the image. Therefore, MIDP devices must support all five filter types defined by filter method 0.
- MIDP devices are required to read PNG images that are encoded with either interlace method 0 (None) or interlace method 1 (Adam7). Image loading in MIDP is synchronous and cannot be overlapped with image rendering, and so there is no advantage for an application to use interlace method 1. Support for decoding interlaced images is required for compatibility with PNG and for the convenience of developers who may already have interlaced images available.

The PLTE chunk. Palette-based images must be supported.

The IDAT chunk. Image data may be encoded using any of the 5 filter types defined by filter method 0 (None, Sub, Up, Average, Paeth).

The IEND chunk. This chunk must be found in order for the image to be considered valid.

Ancillary chunk support. PNG defines several 'ancillary' chunks that may be present in a PNG image but are not critical for image decoding. A MIDP implementation may (but is not required to) support any of these chunks. The implementation should silently ignore any unsupported ancillary chunks that it encounters. The defined ancillary chunks are:

        bKGD cHRM gAMA hIST iCCP iTXt pHYs
        sBIT sPLT sRGB tEXt tIME tRNS zTXt

### Reference

Portable Network Graphics Specification. Version 1.0. W3C Recommendation, October 1, 1996. http://www.w3.org/TR/REC-png.html . Also available as RFC 2083, http://www.ietf.org/rfc/rfc2083.txt .

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 source)` Creates an immutable image from a source 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 new 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. The width and height of the image must both be greater than zero.

  Parameters:
    `width` - the width of the new image, in pixels
    `height` - the height of the new image, in pixels
  Returns:
    the created image
  Throws:
    IllegalArgumentException - if width or height is less than zero

### createImage

    public static Image createImage(Image source)

  Creates an immutable image from a source image. If the source image is mutable, an immutable copy is created and returned. If the source image is immutable, the implementation may simply return it without creating a new image.

  This method is useful for placing images drawn off-screen into Alert, Choice, Form, and StringItem objects. The application can create an off-screen image using the `createImage(w, h)` method, draw into it using a Graphics object obtained with the `getGraphics()` method, and then create an immutable copy of it with this method. The immutable copy may then be placed into the Alert, Choice, Form, and StringItem objects.

  Parameters:
    `source` - the source image to be copied
  Returns:
    the new, immutable 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 image data in one of the supported image 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 a self-identifying image file format supported by the implementation, such as PNG.

  The imageoffset and imagelength parameters specify a range of data within the imageData byte array. The imageOffset parameter specifies the offset into 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.

  This method is intended for use when loading an image from a variety of sources, such as from persistent storage 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 new 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.

  The newly created Graphics object has the following properties:

  - the destination is this Image object;
  - the clip region encompasses the entire Image;
  - the current color is black;
  - the font is the same as the font returned by `Font.getDefaultFont()`;
  - the stroke style is `SOLID`; and
  - the origin of the coordinate system is located at the upper-left corner of the Image.

  The lifetime of Graphics objects created using this method is indefinite. They may be used at any time, by any thread.

  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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| MID Profile
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a comment or suggestion Version 0.95 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.