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

Posts: 48
Registered: ‎04-07-2011
My Device: 9550
My Carrier: Desktop

How to Calculate RGB values to get Custom Color

Hi all,



           How to calculate RGB values to get custom color and draw that custom color on Bitmap.Give me the suggesions or send the Sample Code.



Thanks & Regards,

Nagarjuna Metla.

Posts: 153
Registered: ‎12-03-2012
My Device: PP
My Carrier: base(kpn)/BE, t-mobile/PL

Re: How to Calculate RGB values to get Custom Color

Check this:



import java.awt.Color;

public class OperaColor extends Color {

  public OperaColor(int r, int g, int b) {

   * Returns the HEX value representing the colour in the default sRGB ColorModel.
   * @return the HEX value of the colour in the default sRGB ColorModel
  public String getHex() {
    return toHex(getRed(), getGreen(), getBlue());

   * Returns a web browser-friendly HEX value representing the colour in the default sRGB
   * ColorModel.
   * @param r red
   * @param g green
   * @param b blue
   * @return a browser-friendly HEX value
  public static String toHex(int r, int g, int b) {
    return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);

  private static String toBrowserHexValue(int number) {
    StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
    while (builder.length() < 2) {
    return builder.toString().toUpperCase();



Pawel Gorny
my apps: http://pawelgorny.com/
PGpgp, Your Reply, Anagrammatist, Texas Hold'em Odds Calculator, Contacts to CSV
If your issue has been solved, please resolve it by marking "Accept as Solution"
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to Calculate RGB values to get Custom Color

awt is java SE, it does not run on BB.

usually you define colors on a desktop environment, i use paint.net for example, and copy over the rgb code.
you can use "0xhexcode" to define a color for BB.

As far as a color picker goes, i never wrote the one i wanted, but you can find some suggestions about it here:

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
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to Calculate RGB values to get Custom Color

I am not clear on what you are asking here, but here goes. 


Most paint packages will give you RGB.  There is no need to calculate it. 


Colors on BB devices are represented by integers.  If you view this color in hex, it will look like


where AA is the alpha and RGB is as you would expect.  So


is just full on Red.

This is pretty much what the previous post is telling you. 


To paint a color onto a Bitmap, you will get the <Graphics> context, and then use

<graphics>.setColor(<custom color>);






Hopefully that is enough, if not, then can you ask the question a different way to make it clearer.