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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
j_h
Contributor
Posts: 12
Registered: ‎08-21-2012
My Device: .
My Carrier: att

Failing to Display PNG (IllegalArgumentException)

I'm attempting to display a static image in my blackberry application. I've tried multiple ways,

 

EncodedImage.createEncodedImage, Bitmap.createBitmapFromPNG, Bitmap.createBitmapFromBytes

 

All of them fail with IllegalArgumentException. The data is read in from the SD card and i can navigate to the image and it displays fine in the Blackberry image viewer.

 

FileConnection fc = (FileConnection) Connector.open(filename)
if(fc.exists())
{
InputStream in_stream = fc.openInputStream();
byte[] data = IOUtilities.streamToBytes(in_stream);
in_stream.close();
fc.close()
Bitmap bmpImg = Bitmap.CreateBitmapFrom Bytes(data,0,data.length,1);
}

 Is effectively my code, tried with all those different methods. All bailing with IllegalArgumentException at the data processing part.

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

Re: Failing to Display PNG (IllegalArgumentException)

If the image is static, you could always include in the assets and then get it using Bitmap.getBitmapResource(....);

 

Can you confirm the length of the data array that you read and whether or not the bytes contain what you expect given the file on the SD Card (perhaps use some hex editor on the file). 

 

If neither of these are going to work, then I suspect you might need to put the file that is causing your problems somewhere so that we can get it and try it. 

j_h
Contributor
Posts: 12
Registered: ‎08-21-2012
My Device: .
My Carrier: att

Re: Failing to Display PNG (IllegalArgumentException)

Verified that the data is correct. Still no dice. I haven't seen any code examples but is it possible to play it through the media player like i could an audio file? e.g. 

Player p = Manager.createPlayer(file_path);
p.realize();
p.prefetch();
p.start();

 I threw together a test and it failed, but the validity of that test could be questionable. Lol.

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

Re: Failing to Display PNG (IllegalArgumentException)

OK, any chance of putting the file anywhere we can look at ourselves?

Highlighted
j_h
Contributor
Posts: 12
Registered: ‎08-21-2012
My Device: .
My Carrier: att

Re: Failing to Display PNG (IllegalArgumentException)

So I solved this all by just opening it up in the browser/media player. I guess its PNG handling is a bit better. This has lead to a new question though. I have it going through a variety of types of files including audio. Is there a way of getting PlayerListener like callbacks from the native media player? Both when I open the files using BrowserSession or using something such as Registry.invoke() the default player is opened, however i can't get callbacks from it.

 

Thoughts?