|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.system.EncodedImage
public abstract class EncodedImage
Encapsulates encoded images of various formats.
To decode an image, first call EncodedImage.createEncodedImage to generate an instance of EncodedImage, and then call getBitmap.
This class can only be extended by RIM because it contains one or more abstract methods with package access.
// Create an EncodedImage from bytes EncodedImage image = EncodedImage.createEncodedImage(imageData, 0, imageData.length); screen.add(new BitmapField(image.getBitmap())); // Create an encoded image from provided name resource EncodedImage eImage = EncodedImage.getEncodedImageResource( "img/new.png" ) // A scaled EncodedImage EncodedImage scaledIcon = icon.scaleImage32( scaleX, scaleY );Set the decoding mode
Invoke EncodedImage.setDecodeMode() to set the decoding mode of the image.
Provide one of the following modes as a parameter to the method:
DECODE_ALPHA
: Decodes an alpha channel, if one exists (this is the default mode)
DECODE_NATIVE
: Forces the bitmap to be decoded to the native bitmap type of the handheld software
DECODE_READONLY
: Marks the decoded bitmap as read-only
Set the scaling factor
To set the integer factor that is used to downscale an image when decoding, invoke EncodedImage.setScale(). The image is scaled by the inverse of the integer specified by the scale parameter. For example, if you set the scaling factor to 2, the image is decoded at 50% of its original size.
PNGEncodedImage
,
JPEGEncodedImage
,
GIFEncodedImage
,
WBMPEncodedImage
,
BMPEncodedImage
,
TIFFEncodedImage
,
ICOEncodedImage
Field Summary | ||
---|---|---|
static int |
DECODE_ALPHA
Decodes an alpha channel if there is one. |
|
static int |
DECODE_NATIVE
Forces the bitmap to be decoded to the native bitmap type of the device. |
|
static int |
DECODE_NO_DITHER
Don't dither when decoding. |
|
static int |
DECODE_READONLY
Marks the decoded bitmap as readonly. |
|
static int |
IMAGE_TYPE_BMP
Indicates that an image is encoded in the BMP format. |
|
static int |
IMAGE_TYPE_GIF
Indicates that an image is encoded in the GIF format. |
|
static int |
IMAGE_TYPE_ICO
Indicates that an image is encoded in the ICO format. |
|
static int |
IMAGE_TYPE_JPEG
Indicates that an image is encoded in the JPEG format. |
|
static int |
IMAGE_TYPE_PNG
Indicates that an image is encoded in the PNG format. |
|
static int |
IMAGE_TYPE_TIFF
Indicates that an image is encoded in the TIFF format. |
|
static int |
IMAGE_TYPE_WBMP
Indicates that an image is encoded in the WBMP format. |
Method Summary | ||
---|---|---|
static EncodedImage |
createEncodedImage(byte[] data,
int offset,
int length)
Creates an EncodedImage from bytes. |
|
static EncodedImage |
createEncodedImage(byte[] data,
int offset,
int length,
String mimeType)
Creates an EncodedImage from bytes. |
|
int |
getAlphaType(int frameIndex)
Gets the bitmap type for the given frame's alpha channel. |
|
Bitmap |
getBitmap()
Returns a bitmap of this image. |
|
Bitmap |
getBitmap(int frameIndex)
Returns a bitmap image of the specified frame. |
|
abstract int |
getBitmapType(int frameIndex)
Gets the bitmap type for the given frame. |
|
byte[] |
getData()
Returns the encoded data of this image. |
|
int |
getDecodeMode()
Gets the decoding mode for the image. |
|
static EncodedImage |
getEncodedImageResource(String name)
Creates an encoded image from provided name resource. |
|
static EncodedImage |
getEncodedImageResource(String module,
String name)
Creates an encoded image from provided named resource found in module. |
|
int |
getFrameCount()
Returns the number of frames in this image. |
|
int |
getFrameHeight(int frameIndex)
Returns the height in pixels of the specified frame. |
|
boolean |
getFrameMonochrome(int frameIndex)
Returns true if the specified frame is monochrome. |
|
boolean |
getFrameTransparency(int frameIndex)
Returns true if the specified frame has transparency information. |
|
int |
getFrameWidth(int frameIndex)
Returns the width in pixels of the specified frame. |
|
int |
getHeight()
Returns the (unscaled) height of this image in pixels. |
|
int |
getImageHeight(int scaledHeight)
Returns the source image height of scaledHeight in pixels. |
|
int |
getImageType()
Returns this image's encoding format. |
|
int |
getImageWidth(int scaledWidth)
Returns the source image width of scaledWidth in pixels. |
|
int |
getLength()
Returns the length of the encoded image data. |
|
abstract String |
getMIMEType()
Return the commonly known MIME type associate for this encoded image object. |
|
MetaDataControl |
getMetaData()
Gets the metadata for this image. |
|
int |
getOffset()
Returns the offset into the data where the encoded image begins. |
|
int |
getScale()
Gets the scale that is to be used when decoding this image. |
|
int |
getScaleX32()
Gets the x scale that is to be used when decoding this image. |
|
int |
getScaleY32()
Gets the y scale that is to be used when decoding this image. |
|
int |
getScaledFrameHeight(int frameIndex)
Returns the scaled height in pixels of the specified frame. |
|
int |
getScaledFrameWidth(int frameIndex)
Returns the scaled width in pixels of the specified frame. |
|
int |
getScaledHeight()
Returns the scaled height of this image in pixels. |
|
int |
getScaledHeight(int srcHeight)
Returns the scaled height of srcHeight image in pixels. |
|
int |
getScaledWidth()
Returns the scaled width of this image in pixels. |
|
int |
getScaledWidth(int srcWidth)
Returns the scaled width of srcWidth in pixels. |
|
static Enumeration |
getSupportedMIMETypes()
Returns a list of the supported MIME image types. |
|
int |
getWidth()
Returns the (unscaled) width of this image in pixels. |
|
boolean |
hasTransparency()
Returns true if this image has transparency. |
|
boolean |
isAnimated()
Returns true if the image is considered animated. |
|
static boolean |
isMIMETypeSupported(String mimeType)
Determines whether or not the specified MIME type is supported. |
|
boolean |
isMonochrome()
Returns true if this is a monochrome image. |
|
EncodedImage |
scaleImage32(int scaleX,
int scaleY)
Returns a copy of this encoded image, but with its x and y scales set to scaleX
and scaleY , respectively. |
|
EncodedImage |
scaleImageToFill(int desiredWidth,
int desiredHeight)
Returns a copy of this EncodedImage scaled to fill the desired dimensions Note: This method does not crop the image (the image can remain larger than one of the desired dimensions). |
|
void |
setDecodeMode(int decodeMode)
Sets the decoding mode for the image. |
|
void |
setScale(int scale)
Deprecated. Use EncodedImage.scaleImage32(int, int) |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DECODE_ALPHA
public static final int DECODE_NATIVE
public static final int DECODE_READONLY
public static final int DECODE_NO_DITHER
public static final int IMAGE_TYPE_GIF
public static final int IMAGE_TYPE_PNG
public static final int IMAGE_TYPE_JPEG
public static final int IMAGE_TYPE_WBMP
public static final int IMAGE_TYPE_BMP
public static final int IMAGE_TYPE_TIFF
public static final int IMAGE_TYPE_ICO
Method Detail |
---|
public static EncodedImage createEncodedImage(byte[] data, int offset, int length)
EncodedImage
from bytes.
A new instance of the appropriate EncodedImage
subclass
is returned. If the image format is not recognized, an
IllegalArgumentException
is thrown.
This method accepts an encoding of the image in a byte array format. An image encoding can be obtained by either of the following methods:
First, when an image is added to a project in the IDE, the image resource becomes available to the developer.
Second, the image encoding can be obtained manually by converting the binary image file to a java byte array. This is accomplished using the following procedure:
If done correctly, the file will contain a valid Java byte array containing the image encoding.
data
- The byte array containing the encoded image data.offset
- The starting offset of the encoded image data in the array.length
- The length in bytes of the encoded image data,
or -1 to indicate the entire array should be used.PNGEncodedImage
,
JPEGEncodedImage
,
GIFEncodedImage
,
WBMPEncodedImage
,
BMPEncodedImage
,
TIFFEncodedImage
,
ICOEncodedImage
public static EncodedImage createEncodedImage(byte[] data, int offset, int length, String mimeType)
EncodedImage
from bytes.
A new instance of the appropriate EncodedImage
subclass is returned. If the image format does not match the MIME
type, or the image data is otherwise invalid an
IllegalArgumentException
is thrown. If the MIME
type is null then the system will attempt to infer the image type
from the image data.
data
- The byte array containing the encoded image data. (NOT base64 encoded)offset
- The starting offset of the encoded image data in the array.length
- The length in bytes of the encoded image data,
or -1 to indicate the entire array should be used.mimeType
- The MIME type of the image data.
The following MIME types are supported:
IllegalArgumentException
- Thrown if the specified mime type is invalid.public final int getAlphaType(int frameIndex)
frameIndex
- The index of the frame for which to return the alpha channel.
public Bitmap getBitmap()
This method decodes the image represented by this EncodedImage and returns a Bitmap. This call can be expensive.
Bitmap
representation of the image.public Bitmap getBitmap(int frameIndex)
This method decodes the given frame of the image represented by this EncodedImage. This call can be expensive.
frameIndex
- The frame in question.
Bitmap
representation of the image frame.public abstract int getBitmapType(int frameIndex)
frameIndex
- The index of the frame for which to return the bitmap type.
getBitmap
.public final byte[] getData()
public int getDecodeMode()
public static EncodedImage getEncodedImageResource(String name)
This method looks for the resource in both the .cod file that called this method and any .cod files that it relies on. The resource files are automatically generated by the compiler when a new graphic (PNG, GIF, or, JPG) is added to a project.
name
- Name of the encoded image resource.
NullPointerException
- If the name parameter is null.public static EncodedImage getEncodedImageResource(String module, String name)
This method looks for the resource in both the .cod file that called this method and any .cod files that it relies on. The resource files are automatically generated by the compiler when a new graphic (PNG, GIF, or, JPG) is added to a project.
module
- Name of the module containing the encoded image resource. If
not specified, the name of the calling module is used.name
- Name of the encoded image resource.
NullPointerException
- If the name parameter is null.public int getFrameCount()
public boolean isAnimated()
public int getFrameHeight(int frameIndex)
frameIndex
- The frame in question.
public boolean getFrameMonochrome(int frameIndex)
frameIndex
- The frame in question.
true
if this frame is monochrome,
false
otherwise.public boolean getFrameTransparency(int frameIndex)
frameIndex
- The frame in question.
true
if this frame contains transparency,
false
otherwise.public int getFrameWidth(int frameIndex)
frameIndex
- The frame in question.
public int getHeight()
public int getImageType()
public final int getLength()
getData
.EncodedImage.getOffset()
public MetaDataControl getMetaData()
public abstract String getMIMEType()
String
representing the MIME type generally associated with this object.public final int getOffset()
getData
.EncodedImage.getLength()
public int getScale()
Images can be downscaled by an integer factor when decoding. This is a more efficient way of scaling instead of decoding the image normally and using Graphics to scale.
public int getScaledFrameHeight(int frameIndex)
frameIndex
- The frame in question.
public int getScaledFrameWidth(int frameIndex)
frameIndex
- The frame in question.
public final int getScaledHeight()
public final int getScaledWidth()
public final int getScaledWidth(int srcWidth)
public final int getScaledHeight(int srcHeight)
public final int getImageWidth(int scaledWidth)
public final int getImageHeight(int scaledHeight)
public int getScaleX32()
Fixed32
number representing the
x-scaling factor (0 < scale
< 1 for upscaling,
scale
> 1 for downscaling).public int getScaleY32()
Fixed32
number representing the
y-scaling factor (0 < scale
< 1 for upscaling,
scale
> 1 for downscaling).public static Enumeration getSupportedMIMETypes()
This method returns an Enumeration containing Strings representing the MIME image types that the device supports (in lowercase). Note that MIME types are not case sensitive.
PNG format images are guaranteed to be supported.
public int getWidth()
public boolean hasTransparency()
true
if this image contains transparency,
false
otherwise.public static boolean isMIMETypeSupported(String mimeType)
mimeType
- the MIME type in question. It is not case sensitive.
NullPointerException
- when mimeType is nullpublic boolean isMonochrome()
true
if this image is monochrome,
false
otherwise.public void setDecodeMode(int decodeMode)
DECODE_ALPHA
, DECODE_NATIVE
,
DECODE_NO_DITHER
or DECODE_READONLY
(described above). The default decode mode is DECODE_ALPHA
.
decodeMode
- the decoding mode to be used for this image.public void setScale(int scale)
EncodedImage.scaleImage32(int, int)
Images can be downscaled by an integer factor when decoding. This is a more efficient way of scaling instead of decoding the image normally and using Graphics to scale.
scale
- The downscale factor.
IllegalArgumentException
- Thrown if scale is less than 1.public EncodedImage scaleImage32(int scaleX, int scaleY)
scaleX
and scaleY
, respectively. Both provided scale values must be
Fixed32
numbers (0 < scale
< 1 for upscaling, and scale
> 1 for downscaling).
scaleX
- The x-scaling factor (0 < scaleX
< 1 for upscaling,
and scaleX
> 1 for downscaling). Must be a
Fixed32
number.scaleY
- The y-scaling factor (0 < scaleY
< 1 for upscaling,
and scaleY
> 1 for downscaling). Must be a
Fixed32
number.
scaleX
and scaleY
, respectively.
IllegalArgumentException
- if scaleX
or scaleY
is
<= 0.public EncodedImage scaleImageToFill(int desiredWidth, int desiredHeight)
Note: This method does not crop the image (the image can remain larger than one of the desired dimensions). Note 2: This method will not stretch the encoded image. If either original dimension is smaller than the desired the image will not be scaled.
desiredWidth
- the desired width in pixels of the encoded imagedesiredHeight
- the deisred height in pixels of the encoded image
IllegalArgumentException
- if desiredWidth
or desiredHeight
is
<= 0.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal