mwt.midp2
Class ImageUtil

java.lang.Object
  extended by mwt.Skin
      extended by mwt.midp2.ImageUtil

public final class ImageUtil
extends Skin

An image utility class for MIDP2 devices.


Warning: this documentation was not reviewed.
This class extends Skin implementing a new createBuffer(int, int) method that allows transparency. (Check Skin.createBuffer(int, int)). To create an instance use createSkin(Image[], int). If the given images are resized, they do not lose the alpha channel.


To resize or paint an image, use the static methods imageResize(Image, int) and imageColor(Image, int).

This class offers a workaround to draw into immutable/buffered images.
There is no way to create a mutable image as a buffer and draw into it preserving the alpha channels. (only immutable images have alpha channels). The bright-pink color is used to simulate the alpha channel.
Example:

 Image buffer = Image.createImage(width, height);
 ImageUtil.alphaPrepare(buffer);
 Graphics g = buffer.getGraphics();
 [ g.draws ]
 Image alphaImage = ImageUtil.alphaProcess(buffer);
 

Since:
1.2

Method Summary
static void alphaPrepare(javax.microedition.lcdui.Image mutable)
          Fills the given mutable image with the mask color (bright pink).
static javax.microedition.lcdui.Image alphaProcess(javax.microedition.lcdui.Image buffer)
          Creates a new immutable image processing the given image pixels with alphaProcess(int[]).
static void alphaProcess(int[] pixels)
          Proccesses the bright pink color intensities as alpha channel values.
protected  javax.microedition.lcdui.Image createBuffer(int width, int height)
          Creates an image that will be used as a buffer.
static Skin createSkin(javax.microedition.lcdui.Image[] images, int newSize)
          Creates an image skin.
static javax.microedition.lcdui.Image imageColor(javax.microedition.lcdui.Image img, int color)
          Creates a new immutable image processing the given image pixels with imageColor(int[], int).
static void imageColor(int[] pixels, int color)
          Processes the given pixels applying the given color.
static javax.microedition.lcdui.Image imageResize(javax.microedition.lcdui.Image img, int newHeight)
          Like imageResize(int[], int, int) but using an image instead.
static int[] imageResize(int[] img, int height, int newHeight)
          Resize an image rgba raw.
 
Methods inherited from class mwt.Skin
clone, copy, paint, paint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createSkin

public static final Skin createSkin(javax.microedition.lcdui.Image[] images,
                                    int newSize)
Creates an image skin. Preserving transparency.

Parameters:
images - The array with 9 images in the correspoding order
newSize - The new size, or 0 to skip resizing
Returns:
the skin
See Also:
Skin

createBuffer

protected javax.microedition.lcdui.Image createBuffer(int width,
                                                      int height)
Description copied from class: Skin
Creates an image that will be used as a buffer.
This method must return an image for the given component size.
An implementation can return null, in such case, no cache is created.
The default implementation is:
        Image buf = Image.createImage(c.getWidth(),c.getHeight());
        this.paint(buf.getGraphics(),c.getWidth(),c.getHeight());
        return buf;
 
MWT handles memory management automatically.
References to this image will be garbage collected when the given component is garbage collected, or when its double buffer property is set to false.

Overrides:
createBuffer in class Skin

imageResize

public static final int[] imageResize(int[] img,
                                      int height,
                                      int newHeight)
Resize an image rgba raw.

Parameters:
img - the image
height - the image's height
newHeight - the new height
Returns:
a new resized image rgba raw

imageResize

public static final javax.microedition.lcdui.Image imageResize(javax.microedition.lcdui.Image img,
                                                               int newHeight)
Like imageResize(int[], int, int) but using an image instead.

Parameters:
img -
newHeight -
Returns:
a new resized image

imageColor

public static final void imageColor(int[] pixels,
                                    int color)
Processes the given pixels applying the given color.
The given pixels are processed like gray scale with alpha values, where the red is the gray scale channel and the green and blue bytes are ignored.

Parameters:
pixels -
color -

imageColor

public static final javax.microedition.lcdui.Image imageColor(javax.microedition.lcdui.Image img,
                                                              int color)
Creates a new immutable image processing the given image pixels with imageColor(int[], int).

Parameters:
img -
color -
Returns:
a new immutable image

alphaPrepare

public static final void alphaPrepare(javax.microedition.lcdui.Image mutable)
Fills the given mutable image with the mask color (bright pink).

Parameters:
mutable -
See Also:
alphaProcess(Image)

alphaProcess

public static final javax.microedition.lcdui.Image alphaProcess(javax.microedition.lcdui.Image buffer)
Creates a new immutable image processing the given image pixels with alphaProcess(int[]).

Parameters:
buffer -
Returns:
an immutable image

alphaProcess

public static final void alphaProcess(int[] pixels)
Proccesses the bright pink color intensities as alpha channel values.

Parameters:
pixels -


Copyright © 2007 MWT-Team. All Rights Reserved.