public static Bitmap
downloadImage()
{
InputStream iStream = null;
EncodedImage bitmap;
Bitmap bmp = null ;
HttpConnection httpConnection = null;
try
{
httpConnection = (HttpConnection) Connector.open("http://www.google.com/ig/images/weather/mostly_cloudy.gif"
+ConnectionInfo.getInstance().getConnectionParameters(),
Connector.READ_WRITE);
httpConnection.setRequestMethod(HttpConnection.GET);
int responseCode =
httpConnection.getResponseCode();
if (responseCode == HttpConnection.HTTP_OK) {
iStream = httpConnection.openInputStream();
byte[] imageData = IOUtilities.streamToBytes(iStream);
bitmap = EncodedImage.createEncodedImage(imageData,
0, imageData.length);
bmp = bitmap.getBitmap();
Dialog.alert(""+bmp);
}
}
catch (Exception e)
{
System.out.println("error:"+e.getMessage());
}
return bmp;
}
No comments:
Post a Comment