下面是我的自定义字段的paint方法:
protected void paint(Graphics graphics) {
new downloadImage();
Bitmap img = downloadImage.connectServerForImage(this.poster);
graphics.drawBitmap(0, 0, 100, 150, img, LEFT, TOP);
}下面是connectServerForImage方法:
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;
}我将我的自定义字段的多个实例放入一个verticalfieldmanager中,但图像会减慢滚动速度。似乎每次我滚动时,它都会再次运行paint方法,即使图像已经下载。
我在想,我需要在另一个线程中下载图像吗?谁来给我指引一个正确的方向。
发布于 2011-12-27 12:29:04
https://stackoverflow.com/questions/8640190
复制相似问题