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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009

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.
Please use plain text.
Developer
Ted_Hopp
Posts: 1,304
Registered: ‎01-21-2009

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.
Please use plain text.
Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009

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.
Please use plain text.
Developer
peter_strange
Posts: 17,630
Registered: ‎07-14-2008

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?

Please use plain text.
Developer
mohitsharma
Posts: 190
Registered: ‎10-22-2009

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.
Please use plain text.