2010-07-09 71 views
2

我需要加载并更新来自URL的图片。来自url的流式图片,android

使用AsyncTask,Iam能够从URL加载图像我需要每10秒从URL重新加载图像。

请帮我解释一下这个问题。

在此先感谢

回答

2

下面的代码工作对我很好,

class DownloadImage extends AsyncTask<Void, Void, Drawable>{ 
     @Override 
     protected Drawable doInBackground(Void... params) { 
      return Util.getImageFromURL(imageURL); 
     } 

     @Override 
     protected void onPostExecute(Drawable d) { 
      getImageIcon().setImageDrawable(d); 
     } 

} 
new DownloadImage().execute(); 

,如果你是显示列表视图图像应按照此 http://github.com/commonsguy/cwac-thumbnail

+0

嗨sohilvassa, 我看到你在imageview中显示来自url的图像。 这张图片是否会不断更新url ?.请让我知道如果我能得到这项工作。 感谢您的回复 – praveenb 2010-07-09 18:18:20

2

@Praveenb 试试以下,

Bitmap bmImg; 
void downloadFile(String fileUrl){ 
URL myFileUrl =null; 
try { 
myFileUrl= new URL(fileUrl); 
} catch (MalformedURLException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} 
try { 
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); 
conn.setDoInput(true); 
conn.connect(); 

InputStream is = conn.getInputStream(); 

bmImg = BitmapFactory.decodeStream(is); 
    // it will decode the input stream and will load the bitmat in bmImg variable 

imView.setImageBitmap(bmImg); 
} catch (IOException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} 
}