BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 09-10-2010, 02:52 PM   #1 (permalink)
Thumbs Must Hurt
Join Date: Oct 2008
Model: 8800
Carrier: AT
Posts: 81
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default EncodedImage doesn't encode

Please Login to Remove!


The below code doesn't work for adding image to the MainScreen,

InputStream input = fconn.openInputStream();

int available = input.available();
byte[] data = new byte[available];
System.out.println("reading");, 0, available);

EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length ); // This line of code doesn't work

Bitmap b = image.getBitmap();
BitmapField picture = new BitmapField(b);
main.add(new LabelField("Data Length:" + data.length));

Could anyone tell me what's wrong i am doing ?
Old 09-10-2010, 04:54 PM   #2 (permalink)
BlackBerry Extraordinaire
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts

What does "doesn't work" mean? Are you getting an exception?

You should be checking to make sure that the file was found. Also, I'm not sure you can use available() the way you are - you might want to trace that out and see what you are getting. Sometimes this only tells you how many bytes are in the current buffer, not the entire size of the file.

The file could also be in some unsupported format.
Old 09-14-2010, 09:04 AM   #3 (permalink)
New Member
RockoAndy's Avatar
Join Date: Sep 2010
Model: 8900
Carrier: Airtel
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts

Hi ru using png images or any other format
the amazing world of
Old 09-18-2010, 04:32 PM   #4 (permalink)
New Member
Join Date: May 2010
Model: bold
Carrier: movistar
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default EncodedImage doesn't encode

I think you are getting corruot data so instead using available use filezise method of FileConnection. For example:

InputStream input = fconn.openInputStream();
byte[] data = new byte[fconn.filesize()];
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Copyright 2004-2014
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.