Troubleshooting guide
50
BlackBerry Java Development Environment Development Guide
Code sample: Drawing a new bitmap using an existing bitmap
Example: DrawDemo.java
/*
* DrawDemo.java
* Copyright (C) 2002-2005 Research In Motion Limited.
*/
package com.rim.samples.docs.drawing;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
/* The DrawDemo.java sample retrieves raw data from a predefined bitmap
image, and then draws a new bitmap using the data. It then displays
the original and restored images. */
public class DrawDemo extends UiApplication {
public static void main(String[] args) {
DrawDemo app = new DrawDemo();
app.enterEventDispatcher();
}
public DrawDemo() {
pushScreen(new DrawDemoScreen());
}
}
final class DrawDemoScreen extends MainScreen {
public DrawDemoScreen() {
super();
LabelField title = new LabelField(“UI Demo”, LabelField.USE_ALL_WIDTH);
setTitle(title);
Bitmap original = Bitmap.getPredefinedBitmap(Bitmap.INFORMATION);
Bitmap restored = new Bitmap(original.getType(), original.getWidth(),
original.getHeight());
Graphics graphics = new Graphics(restored);
// Retrieve raw data from original image.
int[] argb = new int[original.getWidth() * original.getHeight()];
original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(),
original.getHeight());
// Draw new image using raw data retrieved from original image.
try {
graphics.drawRGB(argb, 0, restored.getWidth(), 0, 0, restored.getWidth(),
restored.getHeight());
} catch(Exception e) {