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));
有一个简单的解决方案吗?我在这里弄错了吗?
相关分类