com.sun.lwuit
Class EncodedImage

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

public class EncodedImage
extends Image

An image that only keeps the binary data of the source file used to load it in permanent memory. This allows the bitmap to get collected while the binary data remains, a weak reference is used for caching.


Constructor Summary
protected EncodedImage(int width, int height)
          Allows subclasses to create more advanced variations of this class that lazily store the data in an arbitrary location.
 
Method Summary
static EncodedImage create(byte[] data)
          Creates an image from the given byte array
static EncodedImage create(java.io.InputStream i)
          Creates an image from the input stream
static EncodedImage create(java.lang.String i)
          Creates an image from the input stream
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.
protected  void drawImage(Graphics g, java.lang.Object nativeGraphics, int x, int y, int w, int h)
          Callback invoked internally by LWUIT to draw the image/frame onto the display.
 Graphics getGraphics()
          If this is a mutable image a graphics object allowing us to draw on it is returned.
 int getHeight()
          Returns the height of the image
 byte[] getImageData()
          Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.
protected  Image getInternal()
          Returns the actual image represented by the encoded image, this image will be cached in a weak/soft reference internally.
 int getWidth()
          Returns the width of the image
 boolean isAnimation()
          Returns true if this is an animated image
 boolean isOpaque()
          Indicates whether this image is opaque or not
 void lock()
          This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g. an encoded image might choose to cache itself in RAM.
 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 modifyAlpha(byte alpha, int removeColor)
          Creates a new image instance with the alpha channel of opaque/translucent pixels within the image using the new alpha value.
protected  void resetCache()
          A subclass might choose to load asynchroniously and reset the cache when the image is ready.
 Image rotate(int degrees)
          Returns an instance of this image rotated by the given number of degrees.
 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.
 Image scaledHeight(int height)
          Scales the image to the given height while updating the width based on the aspect ratio of the height
 Image scaledSmallerRatio(int width, int height)
          Scales the image while maintaining the aspect ratio to the smaller size image
 Image scaledWidth(int width)
          Scales the image to the given width while updating the height based on the aspect ratio of the width
 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.
 void toRGB(RGBImage image, int destX, int destY, int x, int y, int width, int height)
          Extracts data from this image into the given RGBImage
 void unlock()
          This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.
 
Methods inherited from class com.sun.lwuit.Image
animate, applyMask, applyMask, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createMask, createSVG, getImage, getRGB, getRGBCached, getSVGDocument, isAlphaMutableImageSupported, isSVG, isSVGSupported, modifyAlphaWithTranslucency
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncodedImage

protected EncodedImage(int width,
                       int height)
Allows subclasses to create more advanced variations of this class that lazily store the data in an arbitrary location.

Parameters:
width - -1 if unknown ideally the width/height should be known in advance
height - -1 if unknown ideally the width/height should be known in advance
Method Detail

resetCache

protected void resetCache()
A subclass might choose to load asynchroniously and reset the cache when the image is ready.


getImageData

public byte[] getImageData()
Returns the byte array data backing the image allowing the image to be stored and discarded completely from RAM.

Returns:
byte array used to create the image, e.g. encoded PNG, JPEG etc.

create

public static EncodedImage create(byte[] data)
Creates an image from the given byte array

Parameters:
data - the data of the image
Returns:
newly created encoded image

create

public static EncodedImage create(java.io.InputStream i)
                           throws java.io.IOException
Creates an image from the input stream

Parameters:
i - the input stream
Returns:
newly created encoded image
Throws:
java.io.IOException - if thrown by the input stream

getInternal

protected Image getInternal()
Returns the actual image represented by the encoded image, this image will be cached in a weak/soft reference internally. This method is useful to detect when the system actually created an image instance. You shouldn't invoke this method manually!

Returns:
drawable image instance

lock

public void lock()
Description copied from class: Image
This callback indicates that a component pointing at this image is initialized, this allows an image to make performance sensitive considerations e.g. an encoded image might choose to cache itself in RAM. This method may be invoked multiple times.

Overrides:
lock in class Image

unlock

public void unlock()
Description copied from class: Image
This callback indicates that a component pointing at this image is now deinitilized This method may be invoked multiple times.

Overrides:
unlock in class Image

create

public static EncodedImage create(java.lang.String i)
                           throws java.io.IOException
Creates an image from the input stream

Parameters:
i - the resource
Returns:
newly created encoded image
Throws:
java.io.IOException - if thrown by the input stream

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

rotate

public Image rotate(int degrees)
Description copied from class: Image
Returns an instance of this image rotated by the given number of degrees. By default 90 degree angle divisions are supported, anything else is implementation dependent. This method assumes a square image. Notice that it is inefficient in the current implementation to rotate to non-square angles,

E.g. rotating an image to 45, 90 and 135 degrees is inefficient. Use rotatate to 45, 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.

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

modifyAlpha

public Image modifyAlpha(byte alpha,
                         int removeColor)
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
removeColor - pixels matching this color are made transparent (alpha channel ignored)
Returns:
Translucent/Opaque image based on the alpha value and the pixels of this image

getGraphics

public Graphics getGraphics()
Description copied from class: Image
If this is a mutable image a graphics object allowing us to draw on it is returned.

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

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

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

drawImage

protected void drawImage(Graphics g,
                         java.lang.Object nativeGraphics,
                         int x,
                         int y,
                         int w,
                         int h)
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
w - the width to occupy
h - the height to occupy

toRGB

public void toRGB(RGBImage image,
                  int destX,
                  int destY,
                  int x,
                  int y,
                  int width,
                  int height)
Description copied from class: Image
Extracts data from this image into the given RGBImage

Overrides:
toRGB in class Image
Parameters:
image - RGBImage that would receive pixel data
destX - x location within RGBImage into which the data will be written
destY - y location within RGBImage into which the data will be written
x - location within the source image
y - location within the source image
width - size of the image to extract from the source image
height - size of the image to extract from the source image

scaledWidth

public Image scaledWidth(int width)
Description copied from class: Image
Scales the image to the given width while updating the height based on the aspect ratio of the width

Overrides:
scaledWidth in class Image
Parameters:
width - the given new image width
Returns:
the newly created image

scaledHeight

public Image scaledHeight(int height)
Description copied from class: Image
Scales the image to the given height while updating the width based on the aspect ratio of the height

Overrides:
scaledHeight in class Image
Parameters:
height - the given new image height
Returns:
the newly created image

scaledSmallerRatio

public Image scaledSmallerRatio(int width,
                                int height)
Description copied from class: Image
Scales the image while maintaining the aspect ratio to the smaller size image

Overrides:
scaledSmallerRatio in class Image
Parameters:
width - the given new image width
height - the given new image height
Returns:
the newly created image

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

isAnimation

public boolean isAnimation()
Description copied from class: Image
Returns true if this is an animated image

Overrides:
isAnimation in class Image
Returns:
true if this image represents an animation

isOpaque

public boolean isOpaque()
Description copied from class: Image
Indicates whether this image is opaque or not

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