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
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified
Accepted Solution

Draw circle with gradient color

Dear all,

 Anyone know how to use Graphics to draw a circle with gradient color?

Thanks for help

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Draw circle with gradient color

Use the Graphics.drawShadedPath() method.

Please use plain text.
Developer
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

Re: Draw circle with gradient color

thanks for your suggestion

 

Would you tell me how to use drawShadedPath() to draw a circle?

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Draw circle with gradient color

Here is some very simple code that should work.

 

 

//xc = x center
//yc = y center
//
//  Circle diagram
//           (xc-r),(yc-r){col2}  xc,(yc-r){col3) (xc+r),(yc-r){col4}
//           (xc-r), yc   {col1}  [xc, yc]        (xc+r),yc    {col5}
//           (xc-r),(yc+r){col8}  xc,(yc+r){col7} (xc+r),(yc+r){col6} 

int [] xpts = { (xc-r), (xc-r), xc, (xc+r), (xc+r), (xc+r), xc, (xc-r) };
int [] ypts = { yc, (yc-r), (yc-r), (yc-r), yc, (yc+r), (yc+r), (yc+r) };
byte [] types = { Graphics.CURVEDPATH_END_POINT, 
                  Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
                  Graphics.CURVEDPATH_END_POINT, 
                  Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
                  Graphics.CURVEDPATH_END_POINT, 
                  Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
                  Graphics.CURVEDPATH_END_POINT, 
                  Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT };
int [] colors = { col1, col2, col3, col4, col5, col6, col7, col8 };

graphics.drawShadedPath(xpts,ypts,types,colors,null);

 

 

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Draw circle with gradient color

Hi CMY,

 

am working with 4.7 version. i tried to execute ur code, but it showed me an error at

graphics.drawShadedPath(xpts,ypts,types,colors,null);

and my eclipse ide  allowed me to change to

g.drawShadedFilledPath(xpts,ypts,types,colors,null);

 

is there any version differences??

 

 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: Draw circle with gradient color

Graphics.shadedFilledPath() is the correct function. I was writing it from memory and just had the function name wrong.

Please use plain text.