0
這是我用來獲取圖像形式的URL代碼,但我越來越blanck屏幕請幫助。 代碼爲HttpConnection的:從url黑莓顯示圖像
StringBuffer raw = new StringBuffer();
HttpConnection _c = null;
InputStream _is = null;
try
{
_c = (HttpConnection)Connector.open(url);
_c.getHeaderField("Location");
int rc = _c.getResponseCode();
if (rc != HttpConnection.HTTP_OK)
{
throw new IOException("HTTP response code: " + rc);
}
_is = _c.openInputStream();
_c.getType();
int len = (int)_c.getLength();
{
data = new byte[256];
int size = 0;
while (-1 != (len = _is.read(data)))
{
raw.append(new String(data, 0, len));
size += len;
}
String retVal = raw.toString();
// .alert(retVal);
return retVal+"URL is"+url;
}
}
catch (Exception e)
{
throw new IllegalArgumentException("Not an HTTP URL");
}
finally
{
if (_is != null)
_is.close();
if (_c != null)
_c.close();
}
代碼從perticuler URL得到圖片:
public static Bitmap getImage(String url)
{
Bitmap bitmap;
EncodedImage bmp = EncodedImage.createEncodedImage(data, 0, data.length);
bitmap=bmp.getBitmap();
return bitmap;
}
下面的代碼我使用到MainScreen顯示圖像:
Bitmap bt=HttpUtils.getImage("http://www.eng.chula.ac.th/files/building.jpg");
BitmapField bmp=new BitmapField(bt);
bmp.setBitmap(bt);
add(bmp);
C你告訴我如何異步? – JoVinz 2012-04-27 10:02:00
在線程中運行此行'http_image_data_extrator.getWebData(url,this);'以避免阻塞。 – Rupak 2012-04-27 12:15:06
Thanx我從url獲得圖像..現在我將它們添加到listfield。我希望當我運行應用程序時,我希望在滾動中獲取圖像的空白列表... – JoVinz 2012-05-03 13:23:51