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
Highlighted
Developer
Posts: 95
Registered: ‎03-22-2009
My Device: Torch 9800 & Bold 9700
Accepted Solution

Gradient - Poor Quality

I've taken a look around the forum and found that this is used by a few people to make a gradient for the background of a screen:

 

int[] xInds = new int[]{0, 0,getExtent().width, getExtent().width};
int[] yInds = new int[]{0, getExtent().height, getExtent().height,0};
               									     
final int[] cols = new int[]{Color.DEEPSKYBLUE, Color.LIGHTBLUE, Color.LIGHTBLUE, Color.DEEPSKYBLUE};
               									     
g.drawShadedFilledPath(xInds, yInds, null, cols, null);

 This gives me an output of:

gradient.PNG

 

If you look close, you can see batches of color, which isn't very gradient like.

 

Can anyone offer any advice?

 

Thanks!

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Gradient - Poor Quality

It is done like that on purpose for performance issues I think. The gradient used to be smooth but after a certain build in OS 4.7 I think they started doing banded gradients to improve the drawing performance.

Developer
Posts: 95
Registered: ‎03-22-2009
My Device: Torch 9800 & Bold 9700

Re: Gradient - Poor Quality

That doesn't sound too good. Especially now that screens are higher resolution.

 

I'd hate to start using images instead due to different devices, screen sizes.

 

Does anyone have and suggestions/workarounds or information on how you do this yourselves?

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Gradient - Poor Quality

Did you check it out on the real device?

 

I do a lot of gradients and never really noticed the issue on real devices.  On a PC it looks like **bleep** due to a different amount of bit depth.

Developer
Posts: 95
Registered: ‎03-22-2009
My Device: Torch 9800 & Bold 9700

Re: Gradient - Poor Quality

Yes, I have just loaded it onto a Torch and it looks identical.

 

Any thoughts?

Developer
Posts: 246
Registered: ‎12-13-2010
My Device: Not Specified

Re: Gradient - Poor Quality

Try using BackgroundFactory instead.

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Gradient - Poor Quality

 

you can always create a bitmap background if you want it in high resolution.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Gradient - Poor Quality

This post shows how to create a gradient-filled Bitmap:

 

Re: gradient color in JDE 4.5

----------------------------------------------------------
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
Posts: 95
Registered: ‎03-22-2009
My Device: Torch 9800 & Bold 9700

Re: Gradient - Poor Quality

That seems like a good idea,

 

How would I use this to paint the background?

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

Re: Gradient - Poor Quality

You create a Bitmap and then use Graphics.drawBitmap instead of Graphics.drawShadedFilledPath.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!