您好我查了类似的问题,但我无法解决问题。它不起作用。 我试图从服务器下载一些图像并将它们放在Android应用程序中的ImageViews中。
public class MyAsyncTask extends AsyncTask {
protected String doInBackground(String... params) {
...........
URL urlImagine = new URL("http://s.ytimg.com/yts/img/favicon-vfldLzJxy.ico");
//Version 1:
URLConnection conn = urlImagine.openConnection();
inputStreamImagine = (InputStream)conn.getContent();
..........
//version 2:
inputStreamImagine = urlImagine.openStream();
bufImagine = new BufferedInputStream(inputStreamImagine);
.........
}
}
//Some other class:
..............
//http://stackoverflow.com/questions/15569953/download-image-from-image-url-to-image-view
//version 1:
//Download Image From Image URL to image view
if (inputStreamImagine!=null){
Bitmap bitmap = BitmapFactory.decodeStream(inputStreamImagine);
imageView.setImageBitmap(bitmap);
}
//version 2:
if (bufImagine!=null){
// Convert the BufferedInputStream to a Bitmap
Bitmap bMap = BitmapFactory.decodeStream(bufImagine);
Drawable drawable = new BitmapDrawable(bMap);
imageView.setBackgroundDrawable(drawable);
//iv.setImageDrawable(drawable);
}
我尝试过使用这两个示例,但ImageView没有加载任何图像。 你能帮我吗?