Android:使用Asynctask從Web加載圖像如何用Asynctask替換以下代碼行?你如何從Asynctask“取回”位圖?謝謝。ImageView mChart = (ImageView) findViewById(R.id.Chart);String URL = "http://www...anything ...";mChart.setImageBitmap(download_Image(URL));public static Bitmap download_Image(String url) {
//---------------------------------------------------
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e("Hub","Error getting the image from server : " + e.getMessage().toString());
}
return bm;
//---------------------------------------------------
}我想過這樣的事情:替換:mChart.setImageBitmap(download_Image(graph_URL));通過類似的東西:mChart.setImageBitmap(new DownloadImagesTask().execute(graph_URL));有一個(gè)簡單的解決方案嗎?我在這里弄錯(cuò)了嗎?
- 3 回答
- 0 關(guān)注
- 308 瀏覽
添加回答
舉報(bào)
0/150
提交
取消