Encode an image
-
Import the required classes.
import net.rim.device.api.system.EncodedImage;
-
Invoke
EncodedImage.createEncodedImage(). This method uses
the unprocessed image data in the byte array to create an instance of
EncodedImage.
-
Check for an
IllegalArgumentException, which
EncodedImage.createEncodedImage() throws if the byte
array that you provide as a parameter does not contain a recognized image
format.
// Store the contents of the image file.
private byte[] data = new byte[2430];
try {
// Read the image data into the byte array
input.read(data);
} catch (IOException e) {
// Handle exception.
}
try {
EncodedImage image = EncodedImage.createEncodedImage(data, 0, data.length);
} catch (IllegalArgumentException iae) {
System.out.println("Image format not recognized.");
}
Was this information helpful? Send us your comments.