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
Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry
Accepted Solution

Diagonal Gradient in blackberry java

Hi im trying to make draw shapes with Diagonal gradient but the problems is its gradient dosent seem to be right. Below is the code that I have done. Can I ask for any suggestions on how to do this tnx in advance.

 

protected void paint(net.rim.device.api.ui.Graphics graphics) {
        int width = 300;
        int height = 300;
        int[] xPts = {0, width, width, 0};
        int[] yPts = {0, 0, height, height};
        int[] colors = {
                Color.BLACK, Color.BLACK, Color.WHITE, Color.BLACK
        };
        graphics.drawShadedFilledPath(xPts, yPts, null, colors, null);
    }

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Diagonal Gradient in blackberry java

Try:

 

        int[] colors = {
                Color.BLACK, Color.GREY, Color.WHITE, Color.GREY

        };

Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: Diagonal Gradient in blackberry java

It works be but value seems to be hardcoded because my diagonal gradient is in a method and I pass 2 colors in it but thanks I think I can find a way to get the middle of 2 colors

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Diagonal Gradient in blackberry java

You are right to be careful about doing this, you can't just add and then divide by 2?  You need to find the middle value for each of the Red, Green and Blue components.

Contributor
Posts: 41
Registered: ‎04-24-2012
My Device: storm
My Carrier: blackberry

Re: Diagonal Gradient in blackberry java

Hi i've found 1 instance in using the (color1 + color2) / 2 algo seems to get the wrong color. It is when im trying to get the middle color of blue and yellow I think the problem is that the rgb color of yellow is red - 255 green 255 blue 0 and the rgb color of blue is red - 0, green 0, blue 255 so when I use the (color1+color2) / 2
it becomes red - 127 green 127 blue 127 which is white. Im expecting sort of a violet color Is this the right way to get the middle color of gradients?

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Diagonal Gradient in blackberry java

Good point, my suggestion won't work will it!

 

Honestly not sure how to find a middle color from two RGB values.  I think I would Google it.....