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
Dooleyj
Posts: 43
Registered: ‎05-13-2010
My Device: Blackberry 8520
My Carrier: T-Mobile
Accepted Solution

CreateBitmapFromBytes

Hello I am trying to create a bitmap from the web using CreateBitmapFromBytes inside the Bitmap class. 

 

I create a input stream and use the IOUtilities to convert the input stream to a byte array. After that I use the byte[] to create the bitmap. For some reason, it's not crashing but also not working. Any thoughts?

 

 

Bitmap bmp= null;

//create a connection to access the image on the web
StreamConnection imgSC = (StreamConnection)Connector.open(imageURL);

//create input stream from the stream connection
InputStream imgIS = imgSC.openInputStream();

//convert the input stream to a byte array
byte[] imageData = IOUtilities.streamToBytes(imgIS);

//create a bitmap from the byte array	
bmp = Bitmap.createBitmapFromBytes(imageData, 0	, -1, 1);

//assign the bitmap to the bitmap field
DisplayedBitmap.setBitmap(bmp);

 

 

Please use plain text.
Developer
YamilBracho
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: CreateBitmapFromBytes

Please be sure imageData is filled (say, checking imageData.length)

Please use plain text.
Contributor
Dooleyj
Posts: 43
Registered: ‎05-13-2010
My Device: Blackberry 8520
My Carrier: T-Mobile

Re: CreateBitmapFromBytes

[ Edited ]

Tried what you said and there is no error but it is not completing the function. this is the code:

System.out.println("Starting Image Download");
StreamConnection imgSC = (StreamConnection)Connector.open(imageURL);

System.out.println("Connection Established");
InputStream imgIS = imgSC.openInputStream();

System.out.println("Inputstream Open");
byte[] imageData = IOUtilities.streamToBytes(imgIS);	

System.out.println("Byte array written: "+ imageData.length);

 

 

This is the output:

 

Starting Image Download
Connection Established
Starting net_rim_bb_simphonebook
Started net_rim_bb_simphonebook(166)
EF: 20 SIZE: -1
AG,+CPT
AG,-CPT
JVM: bklt @4186: timer
JVM: bklt[1] @4186: idle 11
JVM: bklt @4186: setTimer 11
SHUTTING DOWN SIM SERVER
Exit net_rim_bb_simphonebook(166)

 

from what I can tell, it can't open the inputstream. Correct assumption?

 

EDIT: Forgot to account for deviceside. and wifi. Fixed by appending

 

Please use plain text.