Troubleshooting guide

48
BlackBerry Java Development Environment Development Guide
try {
EncodedImage image = EncodedImage.createEncodedImage(data, 0, data.length);
add(new BitmapField(image.getBitmap()));
} catch (IllegalArgumentException iae) {
System.out.println(“Image format not recognized.”);
}
}
}
}
Drawing and rendering images
Position an image
Draw an image in color
Task Steps
Use an individual field. 1. Invoke the Graphics() constructor.
Bitmap surface = new Bitmap(100, 100);
BitmapField surfaceField = new BitmapField(surface);
Graphics graphics = new Graphics(surface);
2. Add the BitmapField to the screen.
mainScreen.add(surfaceField);
Use the whole screen. 1. Invoke Screen.getGraphics().
Graphics graphics = Screen.getGraphics();
2. Make sure your methods perform their drawing functions within the boundaries of the screen.
graphics.fillRect(10, 10, 30, 30);
graphics.drawRect(15, 15, 30, 30);
Task Steps
Determine whether the
BlackBerry® device supports
color display.
> Invoke Graphics.isColor().
Determine the number of
colors that the BlackBerry
device supports.
>Invoke Graphics.getNumColors().
Set the pixel transparency in
the drawing area.
1. Invoke one of the following methods:
Graphics.setGlobalApha()
Graphics.getGlobalAlpha()
2. Define a global alpha value within the following range:
0 (0x0000): completely transparent
255 (0x00FF): fully opaque