-1

私は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);」にあります。インポートする必要があるものなどはありますか?

画像を画面に描画/追加するにはどうすればよいですか..明らかなものが欠けていることはわかっていますが、それが何であるかわかりませんか? 何か助けてください。

ありがとう

4

1 に答える 1

0

あなたの最大の問題は、IDE を使用していないことです。Eclipse はこの点で非常に優れています。インポート、自動インデント、ハイライトエラーなどについて教えてくれます。

つまり、g.drawBitmap が正しく呼び出されていないことがわかります。g は、ペイントメソッドをオーバーライドして取得するグラフィックス オブジェクトを参照します。

これをどこで描こうとしているのかはわかりませんが、基本的には 2 つのオプションがあります。

  1. BitmapFieldを使用してください。おそらく最高です。
  2. フィールドの paint メソッドをオーバーライドし、drawBitmap を使用して描画します。

BitmapFieldへのリンクが役立つことを願っています。 http://developer.blackberry.com/java/documentation/picture_bitmap_1984826_11.html

于 2013-06-19T07:30:47.177 に答える