com.sun.lwuit
Class RGBImage

java.lang.Object
  extended by com.sun.lwuit.Image
      extended by com.sun.lwuit.RGBImage

public class RGBImage
extends Image

An image that stores its data as an integer RGB array internally, this image cannot be manipulated via Graphics primitives however its array is accessible and modifiable programmatically. This is very useful for 2 distinct use cases.

The first use case allows us to manipulate images in a custom way while still preserving alpha information where applicable.

The second use case allows us to store images in the Java heap which is useful for some constrained devices. In small devices images are often stored in a separate "heap" which runs out eventually, this allows us to place the image in the Java heap which is potentially more wasteful but might sometimes be more abundant.

Note that unless specified otherwise most methods inherited from Image will fail when invoked on this subclass often with a NullPointerException. This image can be drawn on graphics as usual


Constructor Summary
RGBImage(Image img)
          Converts an image to an RGB image after which the original image can be GC'd
RGBImage(int[] rgb, int width, int height)
          Creates an RGB image from scratch the array isn't copied and can be saved and manipulated
 
Method Summary
protected  void drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y)
          Callback invoked internally by LWUIT to draw the image/frame onto the display.
 Graphics getGraphics()
          This method is unsupported in this image type
 int getHeight()
          Returns the height of the image
 int[] getRGB()
          Returns a mutable array that can be used to change the appearance of the image arranged as AARRGGBB.
 int getWidth()
          Returns the width of the image
 boolean isOpaque()
          Indicates if an image should be treated as opaque, this can improve support for fast drawing of RGB images without alpha support.
 Image modifyAlpha(byte alpha)
          Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.
 Image rotate(int degrees)
          Unsupported in the current version, this method will be implemented in a future release
 void scale(int width, int height)
          Scale the image to the given width and height, this is a fast algorithm that preserves translucent information
 Image scaled(int width, int height)
          Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information.
 void setOpaque(boolean opaque)
           
 Image subImage(int x, int y, int width, int height, boolean processAlpha)
          Extracts a subimage from the given image allowing us to breakdown a single large image into multiple smaller images in RAM, this actually creates a standalone version of the image for use.
 
Methods inherited from class com.sun.lwuit.Image
animate, applyMask, applyMask, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, drawImage, getImage, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isAnimation, isSVG, isSVGSupported, lock, modifyAlpha, modifyAlphaWithTranslucency, scaledHeight, scaledSmallerRatio, scaledWidth, toRGB, unlock
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RGBImage

public RGBImage(Image img)
Converts an image to an RGB image after which the original image can be GC'd

Parameters:
img - the image to convert to an RGB image

RGBImage

public RGBImage(int[] rgb,
                int width,
                int height)
Creates an RGB image from scratch the array isn't copied and can be saved and manipulated

Parameters:
rgb - AARRGGBB array
width - width of image
height - height of image
Method Detail

subImage

public Image subImage(int x,
                      int y,
                      int width,
                      int height,
                      boolean processAlpha)
Description copied from class: Image
Extracts a subimage from the given image allowing us to breakdown a single large image into multiple smaller images in RAM, this actually creates a standalone version of the image for use.

Overrides:
subImage in class Image
Parameters:
x - the x offset from the image
y - the y offset from the image
width - the width of internal images
height - the height of internal images
processAlpha - whether alpha should be processed as well as part of the cutting
Returns:
An array of all the possible images that can be created from the source

scaled

public Image scaled(int width,
                    int height)
Description copied from class: Image
Returns a scaled version of this image image using the given width and height, this is a fast algorithm that preserves translucent information. The method accepts -1 to preserve aspect ratio in the given axis.

Overrides:
scaled in class Image
Parameters:
width - width for the scaling
height - height of the scaled image
Returns:
new image instance scaled to the given height and width

scale

public void scale(int width,
                  int height)
Description copied from class: Image
Scale the image to the given width and height, this is a fast algorithm that preserves translucent information

Overrides:
scale in class Image
Parameters:
width - width for the scaling
height - height of the scaled image

rotate

public Image rotate(int degrees)
Unsupported in the current version, this method will be implemented in a future release

Overrides:
rotate in class Image
Parameters:
degrees - A degree in right angle must be larger than 0 and up to 359 degrees
Returns:
new image instance with the closest possible rotation

modifyAlpha

public Image modifyAlpha(byte alpha)
Description copied from class: Image
Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value. Transparent (alpha == 0) pixels remain transparent. All other pixels will have the new alpha value.

Overrides:
modifyAlpha in class Image
Parameters:
alpha - New value for the entire alpha channel
Returns:
Translucent/Opaque image based on the alpha value and the pixels of this image

getGraphics

public Graphics getGraphics()
This method is unsupported in this image type

Overrides:
getGraphics in class Image
Returns:
Graphics object allowing us to manipulate the content of a mutable image

getRGB

public int[] getRGB()
Returns a mutable array that can be used to change the appearance of the image arranged as AARRGGBB.

Overrides:
getRGB in class Image
Returns:
ARGB int array

drawImage

protected void drawImage(Graphics g,
                         java.lang.Object nativeGraphics,
                         int x,
                         int y)
Description copied from class: Image
Callback invoked internally by LWUIT to draw the image/frame onto the display. Image subclasses can override this method to perform drawing of custom image types.

Overrides:
drawImage in class Image
Parameters:
g - the graphics object
nativeGraphics - the underlying native graphics which might be essential for some image types
x - the x coordinate
y - the y coordinate

setOpaque

public void setOpaque(boolean opaque)

isOpaque

public boolean isOpaque()
Indicates if an image should be treated as opaque, this can improve support for fast drawing of RGB images without alpha support.

Overrides:
isOpaque in class Image
Returns:
true if the image is completely opqaque which allows for some heavy optimizations

getWidth

public int getWidth()
Description copied from class: Image
Returns the width of the image

Overrides:
getWidth in class Image
Returns:
the width of the image

getHeight

public int getHeight()
Description copied from class: Image
Returns the height of the image

Overrides:
getHeight in class Image
Returns:
the height of the image