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: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

bitmap from int[]

Hi guys,

 

I am retrieving bitmap in form of int[ ] containing RGB values of pixels from  server. Is there a way to convert this form into bitmap directly w/o converting individual pixel value into byte? I need to do this very frequently.

 

Thanks in advance.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: bitmap from int[]

Follow these steps:

  1. Create a Bitmap of the appropriate size.
  2. Call Graphics.create(Bitmap) to get a Graphics for drawing into the bitmap.
  3. Call drawRGB on the graphics to draw your data into the bitmap.

An alternative is to go through your RGB array and set the high-order (alpha) byte to 0xFF (data[i] |= 0xFF000000) and then just call setARGB for the bitmap directly after step 1.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: bitmap from int[]

I am already using the first one :smileywink:

 

I think second one would be nice if updates are not so frequent.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.
Developer
Posts: 19,616
Registered: ‎07-14-2008
My Device: Not Specified

Re: bitmap from int[]

[ Edited ]

" am retrieving bitmap in form of int[ ] containing RGB values of pixels from  server."

 

I doubt the network connection will supply data fast enough to flood this conversion process.  However why don't you get the Server to send pngs rather than these ints that need conversion?

Developer
Posts: 190
Registered: ‎10-22-2009
My Device: Blackberry Torch

Re: bitmap from int[]

Server is sending bitmaps fast enough. You can think of it as an animation frame by frame.

I don't have control on the server they have their own protocol.

-----------------------------------------------------------------------------------
Please mark posts as solved if you found a solution. Press the kudos button to thank the user who helped you.