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
j_h
Contributor
j_h
Posts: 12
Registered: ‎08-21-2012
My Device: .

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
peter_strange
Posts: 19,609
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
j_h
Posts: 12
Registered: ‎08-21-2012
My Device: .

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
peter_strange
Posts: 19,609
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?

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

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?