我对 Java 和 Blackberry 开发比较陌生,所以我有点挣扎。我正在尝试从屏幕上的 URL 加载和显示图像,这是我用来获取图像的代码:
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("http://upload.wikimedia.org/wikipedia/en/thumb/b/bd/AA_Reckless_%26_Relentless.jpg/220px-AA_Reckless_%26_Relentless.jpg");
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;
g.drawBitmap(250, 120, 150, 150, bitmp, 0, 0);
我遇到的问题是“g.drawBitmap(250, 120, 150, 150, bitmp, 0, 0);" 有什么我应该进口的或类似的东西吗?
我究竟如何将图像绘制/添加到屏幕上。我知道我遗漏了一些明显的东西,但我不知道它是什么?请问有什么帮助吗?
谢谢