Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
dmravyan
Posts: 25
Registered: ‎01-29-2009
My Device: Curve 8330
Accepted Solution

Draw Circles On Top Of Bitmap.

Hi,

I have created a BitmapField and added a Bitmap to it. The bitmapField is then placed inside a HorizontalFieldManager.
What I would like to do is draw circles of a specific diameter at certain locations on top of the Bitmap. What would be the right approach to this??

 

I was thinking Graphics.fillArc(x, y, radius, radius, 0, 360); would do the trick.. but how can I specify which pixels of my BitmapField should be the center of the circle?

 

Code: 

_pMap = Bitmap.getBitmapResource("pMap.png");

centerIMG = new BitmapField();

centerIMG.setBitmap(_pMap);

 

 _fmOnlineMiddle.add(centerIMG);

 

This is where I would like to draw a circle at pixel x = 24, y = 24 of the Bitmap. (radius 6pixels)

 

Any  help would be greatly appreciated.

 

Thanks,

Dave

 

 

 

 

 

 

Please use plain text.
New Developer
adrian_a
Posts: 13
Registered: ‎03-03-2009
My Device: Not Specified

Re: Draw Circles On Top Of Bitmap.

The way I'd do it is extend the BitmapField and overwrite paint(Graphics) to draw the circle.
Please use plain text.
Developer
dmravyan
Posts: 25
Registered: ‎01-29-2009
My Device: Curve 8330

Re: Draw Circles On Top Of Bitmap.

Thanks for your reply Adrian,

 

Would you have some sort of code example for what you are suggesting? I dont really understand how to implement your suggestion.

 

Thanks

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Draw Circles On Top Of Bitmap.

Try this:

 

_pMap = Bitmap.getBitmapResource("pMap.png");

Graphics bitmapGraphicsContext = new Graphics(_pMap);

bitmapGraphicsContext.drawArc(....params...) ;

centerIMG = new BitmapField();

centerIMG.setBitmap(_pMap);

 

 _fmOnlineMiddle.add(centerIMG);

 

 

 

Please use plain text.
Developer
dmravyan
Posts: 25
Registered: ‎01-29-2009
My Device: Curve 8330

Re: Draw Circles On Top Of Bitmap.

Thanks for the example.

 

When I try to implement it I get a "The Constructor Graphics(Bitmap) is undefined" error.

for Graphics bitmapGraphicsContext = new Graphics(_pMap);

I have imported

import javax.microedition.lcdui.Graphics;

and if I import

import net.rim.device.api.ui.Graphics;

it says that they collide.

 

If i remove the lcdui import statement and replace it with the ui.Graphics my new screen doesnt come up.

 

 

 

 

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Draw Circles On Top Of Bitmap.

I meant net.rim.device.api.ui.Graphics class.

 

In case you are using javax.lcdui classes to make user interface you have to stick with javax.lcdui package.

 

Are you using javax.lcdui classes ?

Please use plain text.
New Developer
adrian_a
Posts: 13
Registered: ‎03-03-2009
My Device: Not Specified

Re: Draw Circles On Top Of Bitmap.

try something like this:
       centerIMG = new BitmapField() {

protected void paint(Graphics graphics) {
super.paint(graphics);
// graphics.drawArc(arg0, arg1, arg2, arg3, arg4, arg5) // put the right params for your arc here
}
};

Please use plain text.
Developer
dmravyan
Posts: 25
Registered: ‎01-29-2009
My Device: Curve 8330

Re: Draw Circles On Top Of Bitmap.

Thanks for your suggestions.

 

Something weird is going on with my app.

I am pushing a new screen which displays some labels and bitmaps inside some vertical and horizontal managers.

 

UiApplication.getUiApplication().pushScreen(new Online(_info));

I am not using the lcdui, but when I import the ui.graphics so that i can use Graphics to draw my circles the screen does not display at all.

I am declaring my managers as follows:

 

HorizontalFieldManager _fmOnlineMiddle= new HorizontalFieldManager();

 this is how i loaded the Bitmap:

 

_pMap = Bitmap.getBitmapResource("pMap.png");

Graphics bitmapGraphicsContext = new Graphics(_pMap);

bitmapGraphicsContext.fillArc(24, 24, 12, 12, 0, 360);

bitmapGraphicsContext.setColor(0x00053609);

centerIMG = new BitmapField();

centerIMG.setBitmap(_pMap);

 

_fmOnlineMiddle.add(centerIMG);

 

Any thoughts?

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Draw Circles On Top Of Bitmap.

[ Edited ]

Try to set color before you are drawing the circle.

 

And I recommend to use Color class constants rather than "magic" numbers.

 

For example. Color.RED

Message Edited by tbilisoft on 05-06-2009 09:38 PM
Please use plain text.
Developer
dmravyan
Posts: 25
Registered: ‎01-29-2009
My Device: Curve 8330

Re: Draw Circles On Top Of Bitmap.

Thanks for your help!!

I got it to work.... I think it didnt like my "magic" numbers :smileyhappy:

 

 

 

Please use plain text.