FileDocCategorySizeDatePackage
ImageData.javaAPI DocphoneME MR2 API (J2ME)6682Wed May 02 18:00:08 BST 2007javax.microedition.lcdui

ImageData

public final class ImageData extends Object implements AbstractImageData
AbstractImageData implementation based on putpixel graphics library and stores data on Java heap.

Fields Summary
private int
width
The width, height of this Image
private int
height
private boolean
isMutable
If this Image is mutable.
private byte[]
pixelData
Image pixel data byte array. If this is null, use nativePixelData and nativeAlphaData instead.
private byte[]
alphaData
Image alpha data byte array. If pixelData is null, use nativePixelData instead.
private int
nativePixelData
Image native romized pixel data. Set in native by loadRomizedImage(). Must remain 0 unless pixelData is null.
private int
nativeAlphaData
Image native romized alpha data. Set in native by loadRomizedImage(). Must remain 0 unless pixelData is null.
Constructors Summary
ImageData()
Constructs empty ImageData .

ImageData(int width, int height, boolean isMutable, boolean clearPixelData, boolean allocateAlpha)
Constructs ImageData using passed in width and height. Alpha array is allocated if allocateAlpha is true.

param
width The width of the ImageData to be created.
param
height The height of the ImageData to be created.
param
isMutable true to create mutable ImageData, false to create immutable ImageData
param
clearPixelData if true pixel data whould be set to 0xff for each pixel
param
allocateAlpha true if alpha data should be allocated, false - if not.


        initImageData(width, height, isMutable, allocateAlpha);

        if (clearPixelData) {
            for (int i = 0; i < pixelData.length; i++) {
                pixelData[i] = (byte)0xFF;
            }
        }
    
ImageData(int width, int height, boolean isMutable, byte[] pixelData)
Constructs mutable or immutable ImageData using passed in width, height and pixel data.

param
width The width of the ImageData to be created.
param
height The height of the ImageData to be created.
param
isMutable true to create mutable ImageData, false to create immutable ImageData
param
pixelData byte array that contains pixel data for the ImageData.

        this.width = width;
        this.height = height;
        this.isMutable = isMutable;

        int length = width * height * 2;
        byte[] newPixelData = new byte[length];
        System.arraycopy(pixelData, 0, newPixelData, 0, length);

        this.pixelData = newPixelData;

        
    
Methods Summary
public intgetHeight()
Gets the height of the image in pixels. The value returned must reflect the actual height of the image when rendered.

return
height of the image

        return height;
    
byte[]getPixelData()
Gets pixel data associated with this ImageData instance.

return
byte arra that represents pixel data associated with this ImageData instance.

        return pixelData;
    
public intgetWidth()
Gets the width of the image in pixels. The value returned must reflect the actual width of the image when rendered.

return
width of the image

        return width;
    
public booleanhasAlpha()
Returns true if ImageData contains alpha data.

return
true if ImageData contains alpha data.

        return (alphaData != null || nativeAlphaData != 0);
    
voidinitImageData(int width, int height, boolean isMutable, boolean allocateAlpha)
Initializes mutable or immutable ImageData using passed in width, height. Alpha array is allocated if allocateAlpha is true.

param
width The width of the ImageData to be created.
param
height The height of the ImageData to be created.
param
isMutable true to create mutable ImageData, false to create immutable ImageData
param
allocateAlpha true if alpha data should be allocated, false - if not.

        this.width = width;
        this.height = height;
        this.isMutable = isMutable;

        pixelData = new byte[width * height * 2];

        if (allocateAlpha) {
            alphaData = new byte[width * height];
        } else {
            alphaData = null;
        }
    
public booleanisMutable()
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.

return
true if the image is mutable, false otherwise

        return isMutable;
    
public voidremoveAlpha()
Removes alpha data information

        alphaData = null;