Java DTV API 1.3
18-Nov-2009

com.sun.dtv.lwuit
Class Image

java.lang.Object
  extended by com.sun.dtv.lwuit.Image
Direct Known Subclasses:
StaticAnimation

public class Image
extends Object

Abstracts the underlying platform images allowing us to treat them as a uniform object. In the DTV version of LWUIT, an image always wraps an instance of java.awt.Image. As a consequence, additional functionality has been added in order to expose the wrapped java.awt.Image instance where necessary. The access to the wrapped object is encouraged only if this is really necessary in order to handle a specific LWUIT vs. AWT integration issue. It should not be used for ordinary tasks.


Constructor Summary
Image(Image image)
          Creates a new instance of Image out of the java.awt.Image to be wrapped.
 
Method Summary
static Image createImage(byte[] bytes, int offset, int len)
          Creates an image from a given byte array data.
static Image createImage(Image image)
          Creates an image from the java.awt.Image to be wrapped.
static Image createImage(InputStream stream)
          Creates an image from an InputStream.
static Image createImage(int[] rgb, int width, int height)
          Creates an image from an RGB image.
static Image createImage(int width, int height)
          Creates a buffered Image.
static Image createImage(String path)
          Creates an image from the given path.
 Image getAWTImage()
          Obtains the java.awt.Image wrapped by this Image.
 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.
 int[] getRGB()
          Returns the content of this image as a newly created ARGB array.
 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.
 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, Color removeColor)
          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)
          Returns an instance of this image rotated by the given number of degrees.
 Image scaled(int width, int height)
          Returns a scaled version of this 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Image

public Image(Image image)
Creates a new instance of Image out of the java.awt.Image to be wrapped.

Parameters:
image - thejava.awt.Image to be wrapped
Method Detail

subImage

public 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.

Parameters:
x - x coordinate of upper left corner
y - y coordinate of upper left corner
width - the width of internal images
height - the height of internal images
processAlpha - alphaComposite value
Returns:
An array of all the possible images that can be created from the source
Throws:
IOException

rotate

public Image rotate(int degrees)
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 rotate to 45, 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.

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)
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.

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,
                         Color removeColor)
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.

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

createImage

public static Image createImage(String path)
                         throws IOException
Creates an image from the given path.

Parameters:
path - path where to find image information
Returns:
newly created image object
Throws:
IOException

createImage

public static Image createImage(InputStream stream)
                         throws IOException
Creates an image from an InputStream.

Parameters:
stream - a given InputStream
Returns:
an Image object
Throws:
IOException

createImage

public static Image createImage(int[] rgb,
                                int width,
                                int height)
Creates an image from an RGB image.

Parameters:
rgb - the RGB image array data
width - the image width
height - the image height
Returns:
an image from an RGB image

createImage

public static Image createImage(int width,
                                int height)
Creates a buffered Image.

Parameters:
width - the image width
height - the image height
Returns:
an image in a given width and height dimension

createImage

public static Image createImage(byte[] bytes,
                                int offset,
                                int len)
Creates an image from a given byte array data.

Parameters:
bytes - the array of image data in a supported image format
offset - the offset of the start of the data in the array
len - the length of the data in the array
Returns:
an Image object

createImage

public static Image createImage(Image image)
Creates an image from the java.awt.Image to be wrapped.

Parameters:
image - the java.awt.Image to be wrapped
Returns:
the created instance of Image

getGraphics

public Graphics getGraphics()
If this is a mutable image a graphics object allowing us to draw on it is returned.

Returns:
Graphics object allowing us to manipulate the content of a mutable image

getWidth

public int getWidth()
Returns the width of the image.

Returns:
the width of the image

getHeight

public int getHeight()
Returns the height of the image.

Returns:
the height of the image

getRGB

public int[] getRGB()
Returns the content of this image as a newly created ARGB array.

Returns:
new array instance containing the ARGB data within this image

scaledWidth

public Image scaledWidth(int width)
Scales the image to the given width while updating the height based on the aspect ratio of the width.

Parameters:
width - the given new image width
Returns:
an Image object

scaledHeight

public Image scaledHeight(int height)
Scales the image to the given height while updating the width based on the aspect ratio of the height.

Parameters:
height - the given new image height
Returns:
an Image object

scaledSmallerRatio

public Image scaledSmallerRatio(int width,
                                int height)
Scales the image while maintaining the aspect ratio to the smaller size image.

Parameters:
width - the given new image width
height - the given new image height
Returns:
an Image object

scaled

public Image scaled(int width,
                    int height)
Returns a scaled version of this image using the given width and height, this is a fast algorithm that preserves translucent information.

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

getAWTImage

public Image getAWTImage()
Obtains the java.awt.Image wrapped by this Image.

Returns:
the wrapped java.awt.Image

isAnimation

public boolean isAnimation()
Returns true if this is an animated image.

Returns:
true if image is animation

isOpaque

public boolean isOpaque()
Indicates whether this image is opaque or not.

Returns:
true if the image is completely opaque which allows for some heavy optimizations

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.