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
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A
Accepted Solution

How can you overlay a bitmap with a solid color

Hi

 

I have a set of icons which are all white with a transparent background.  I need to allow the user to change the color of these within the app.  Does anyone know of a way to do this?

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

Re: How can you overlay a bitmap with a solid color

I have never actually done this, but I believe if you have the Bitmap, then you can do this by using get and set ARGB.

 

In essence, you convert the Bitmap to a int array using getARGB().  The int array values contain the pixel color value in the form 0xaarrggbb, where a is the alpha value, rr is the red, bb is the blue and gg is the green.  Because your pixels are all white, all the int values that are white will be 0xaaFFFFFF.  So you will extract the int values, replace the FFFFFF (leaving the aa) with the color you want, leave any pixels  that are not FFFFFF as they are and then put the int values back using setARGB().

 

Give this a try and let us know how you get on.

Developer
Posts: 122
Registered: ‎11-12-2010
My Device: Dev Alpha
My Carrier: N/A

Re: How can you overlay a bitmap with a solid color

Thank you so much for your assistance Peter - this has worked a treat.