I am downloading an image(png) from Network and trying to display it on the screen. I get the image to display properly on the blackberry simulator(4.5) , but when i download the same image on device its all messed up.
Here is the code i am using:
connection = (HttpConnection) Connector.open(url + getConnectionParameters());
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
System.out.println("Response code " + responseCode);
if (responseCode != HttpConnection.HTTP_OK)
{
requestFailed("Unexpected response code: " + responseCode);
connection.close();
return;
}
String contentType = connection.getHeaderField("Content-type");
in = connection.openInputStream();
final byte[] output=IOUtilities.streamToBytes(in);
requestSucceeded(output, contentType);
public void requestSucceeded( byte[] data, String contentType )
{
System.out.println( "** http callback called" );
if( data != null && new String( data ).startsWith( "Exception" ) ) {
System.out.println( "** bitmap data is not suitable.." );
return;
}
EncodedImage image = EncodedImage.createEncodedImage( data, 0, data.length );
if( image != null )
setImage( image );
else
System.out.println( "NEtworkImageField - Image downloaded is null!" );