Blackberry 在黑莓手机上下载并显示图像
我必须开发一个url,其中包括从url下载图像并在blackberry Simulator中显示。在这方面有人可以帮助我吗?此代码将连接给定的url并返回位图对象Blackberry 在黑莓手机上下载并显示图像,blackberry,Blackberry,我必须开发一个url,其中包括从url下载图像并在blackberry Simulator中显示。在这方面有人可以帮助我吗?此代码将连接给定的url并返回位图对象 public static Bitmap connectServerForImage(String url) { HttpConnection httpConnection = null; DataOutputStream httpDataOutput = null; InputStream
public static Bitmap connectServerForImage(String url) {
HttpConnection httpConnection = null;
DataOutputStream httpDataOutput = null;
InputStream httpInput = null;
int rc;
Bitmap bitmp = null;
try {
httpConnection = (HttpConnection) Connector.open(url);
rc = httpConnection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
httpInput = httpConnection.openInputStream();
InputStream inp = httpInput;
byte[] b = IOUtilities.streamToBytes(inp);
EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
return hai.getBitmap();
} catch (Exception ex) {
System.out.println("URL Bitmap Error........" + ex.getMessage());
} finally {
try {
if (httpInput != null)
httpInput.close();
if (httpDataOutput != null)
httpDataOutput.close();
if (httpConnection != null)
httpConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return bitmp;
}
你可以创建一个bimapfield并将该位图指定为
BitmapField bmpFld1=new BitmapField(connectServerForImage(Url));
用于基64字符串解码
try {
mapaByte = Base64InputStream.decode(imagenB64);
Bitmap mapa64 = Bitmap.createBitmapFromBytes(mapaByte, 0, -1, 1);
mapa.setBitmap(mapa64);
}
catch (Exception e) {}
可能重复您第一次问这个问题时的评论。是的。。。。。。迈克尔:你的邮箱号码是什么。。。。我想和你聊天这是我必须扩展到ui应用程序类的代码吗?不需要。。你可以分开保存。在屏幕中添加位图字段。