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
mtatro
Posts: 105
Registered: ‎06-23-2010
My Device: 9000
Accepted Solution

drawArc with line thickness > 1

Hi Everyone,

 

since drawArc will only draw an arc with line thickness of 1, I am looking if someone has a piece of sample code that let's me draw a line with a thickness > 1.

 

thanks in advance.

-matt

Press Kudos if this helped - ;-)
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: drawArc with line thickness > 1

[ Edited ]

I don't have a solution, just to say I've looked at fillArc in the past to try to do this, and I don't think it does the job.

 

Edit:

I would think seriously about an arc image that you scale and paint on. 

Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: drawArc with line thickness > 1

As advanced warning (because I've tried this), shifting by a pixel can sometimes lead to there being "holes" in the areas that are arced -- you'll see pixels that don't get filled.

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: drawArc with line thickness > 1

As a possibility - fillArc with the outer radius and your foreground color, then fillArc with the inner radius and the background color.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: drawArc with line thickness > 1

"fillArc with the outer radius and your foreground color, then fillArc with the inner radius and the background color."

 

Thought about this myself, then wondered how i would get the rectangles the correct size to make sure it all joined up....

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: drawArc with line thickness > 1

 


peter_strange wrote:

"fillArc with the outer radius and your foreground color, then fillArc with the inner radius and the background color."

 

Thought about this myself, then wondered how i would get the rectangles the correct size to make sure it all joined up....


 

1) Calculate the horizontal and vertical difference between the outer and the inner arc.  Let's say vertical is a pixels and horizontal is b pixels. For circles, a will be equal to b.

2)     int previousColor = g.getColor();

      g.setColor(arcColor);

      g.fillArc(x, y, width, height, angle1, angle2);

      g.setColor(g.getBackgroundColor());

      g.fillaArc(x + b, y + a, width - 2 * b, height - 2 * a, angle1, angle2);

      g.setColor(previousColor);

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: drawArc with line thickness > 1

Well done.  Thanks.

 

Tested it myself, here is some code:

 

        Bitmap arcBitmap = new Bitmap(Display.getWidth()/2, Display.getHeight()/2);
        Graphics g = new Graphics(arcBitmap);
        int arcColor = 0x00FF0000; // Red
        int backColor = g.getBackgroundColor();
        int x = 0;
        int y = 0;
        int width = arcBitmap.getWidth();
        int height = arcBitmap.getHeight();
        int b = width/8;
        int a = height/8;
        int angle1 = 45;
        int angle2 = 90;
        int previousColor = g.getColor();
        try {
            g.setColor(arcColor);
            g.fillArc(x, y, width, height, angle1, angle2);
            g.setColor(backColor);
            g.fillArc(x + b, y + a, width - 2 * b, height - 2 * a, angle1, angle2);
        } finally {
            g.setColor(previousColor);
        }
        BitmapField bmf = new BitmapField(arcBitmap, BitmapField.FOCUSABLE);

Developer
mtatro
Posts: 105
Registered: ‎06-23-2010
My Device: 9000

Re: drawArc with line thickness > 1

Thanks to all of you...

 

I am currently sitting in an airport, so I cannot test this until tomorrow.

 

-matt

-matt

Press Kudos if this helped - ;-)
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: drawArc with line thickness > 1

No problem, take your time. Just don't forget to mark the most fitting post as a solution once you confirm that it's working (choose the one with the code so that people coming to this thread with a search can jump to solution and immediately find something useful).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
mtatro
Posts: 105
Registered: ‎06-23-2010
My Device: 9000

Re: drawArc with line thickness > 1

Works like a champ, thanks...

 

Accepted and kudos given :-)

-matt

Press Kudos if this helped - ;-)