MusiGenesis
MusiGenesis

Reputation: 75296

How to do custom drawing on a Bitmap / BitmapField on the BlackBerry?

I want to do something relatively simple: I want to create a Bitmap object entirely in code, draw on it (lines, text, ellipses, rectangles, points etc.), and display it in a BitmapField on the BlackBerry screen.

Can anyone give me a simple code sample that shows how to do this, or a link to a good sample project?

Update: I have this code sample, but it uses a deprecated constructor for Graphics:

Bitmap bmp = new Bitmap(100, 100);
Graphics g = new Graphics(bmp);
g.drawLine(0, 0, 100, 100);
BitmapField bmpField = new BitmapField(bmp);
add(bmpField);

How do I do the same thing, only without using the Graphics constructor that takes a Bitmap?

Upvotes: 2

Views: 981

Answers (2)

David
David

Reputation: 2131

override the paint method:

Bitmap bmp = new Bitmap(100, 100) {
   public void paint(Graphics graphics) {
      graphics.clear();
      // write your code here
      super.paint(graphics);
   }   
};  

Upvotes: 2

Michael Donohue
Michael Donohue

Reputation: 11876

You can use the static factory method on the Graphics class: Graphics.create(Bitmap)

Upvotes: 3

Related Questions