06-05-2009 11:22 AM
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
Solved! Go to Solution.
06-05-2009 11:37 AM
06-05-2009 11:49 AM
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
06-05-2009 11:58 AM
Try this:
_pMap = Bitmap.getBitmapResource("pMap.png");
Graphics bitmapGraphicsContext = new Graphics(_pMap);
bitmapGraphicsContext.drawArc(....params...) ;
centerIMG = new BitmapField();
centerIMG.setBitmap(_pMap);
_fmOnlineMiddle.add(centerIMG);
06-05-2009 01:25 PM
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.
06-05-2009 02:04 PM
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 ?
06-05-2009 02:36 PM
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
}
};
06-05-2009 04:21 PM
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?
06-05-2009 04:37 PM - edited 06-05-2009 04:38 PM
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
06-05-2009 05:10 PM
Thanks for your help!!
I got it to work.... I think it didnt like my "magic" numbers ![]()