Troubleshooting guide

47
2: Using graphics and multimedia
Code sample: Using a raw image to recreate an encoded image
Example: ImageDemo.java
/**
* ImageDemo.java
* Copyright (C) 2001-2005 Research In Motion Limited. All rights reserved.
*/
package com.rim.samples.docs.imagedemo;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import java.io.*;
/* The ImageDemo.java sample retrieves raw data from an image that
is included in its project, and then uses that raw data to
recreate an EncodedImage. */
public class ImageDemo extends UiApplication {
public static void main(String[] args) {
ImageDemo app = new ImageDemo();
app.enterEventDispatcher();
}
public ImageDemo() {
pushScreen(new ImageDemoScreen());
}
}
final class ImageDemoScreen extends MainScreen {
private static final int IMAGE_SIZE = 2430;
private InputStream input;
private byte[] data = new byte[IMAGE_SIZE];
public ImageDemoScreen() {
super();
setTitle(new LabelField(“Image Demo Sample”));
try {
input =
Class.forName(“com.rim.samples.docs.imagedemo.ImageDemo”).getResourceAsStream(“/images/
hellokitty.png”);
} catch (ClassNotFoundException e) {
System.out.println(“Class not found”);
}
if(input == null) {
System.out.println(“Error: input stream is not initialized.”);
} else if (input != null) {
System.out.println(“OK: input stream is initialized.”);
try {
int code = input.read(data);
System.out.println(“Total number of bytes read into buffer: “ + code + “
.”);
} catch (IOException e) {
// Handle exception.
}