我正在使用 Blackberry JDE(9000 模拟器),我想知道是否可以显示来自网络的图像。
目前,我正在查看Bitmap.getBitmapResource
用于显示黑莓应用程序本地图像的教程,但查看 API,我没有看到任何对提供 Web URL 的支持。
还有其他我可以查看的黑莓图像类吗?还是不支持此功能?
我正在使用 Blackberry JDE(9000 模拟器),我想知道是否可以显示来自网络的图像。
目前,我正在查看Bitmap.getBitmapResource
用于显示黑莓应用程序本地图像的教程,但查看 API,我没有看到任何对提供 Web URL 的支持。
还有其他我可以查看的黑莓图像类吗?还是不支持此功能?
You can download image using HTTPConnection and InputStream, create EncodedImage from stream and then display it.
See coderholic - Blackberry WebBitmapField
BTW, you can use IOUtilities.streamToBytes() method to read bytes from InputStream directly!
这是您的问题的代码示例:
HttpConnection httpConn = null;
InputStream inputStream = null;
int ResponseCode = HttpConnection.HTTP_OK;
byte[] ResponseData = null;
try {
httpConn = (HttpConnection) Connector.open(url, Connector.READ, true);
ResponseCode = httpConn.getResponseCode();
if (ResponseCode == HttpConnection.HTTP_OK) {
inputStream = httpConn.openInputStream();
ResponseData = IOUtilities.streamToBytes(inputStream);
}
}
catch(IOException e){
throw new IOException("HTTP response code: "
+ ResponseCode);
}
finally {
try {
inputStream.close();
inputStream = null;
httpConn.close();
httpConn = null;
}
catch(Exception e){}
}
return ResponseData;
如果您想要完全执行此操作的代码(尽管这篇文章很旧,所以我猜您不再需要了)