【问题标题】:streaming image from url, android从 url 流式传输图像,android
【发布时间】:2010-07-09 03:46:28
【问题描述】:

我需要从 URL 加载和更新图像。

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

请帮助我如何解决这个问题。

提前致谢

【问题讨论】:

    标签: android android-emulator android-widget


    【解决方案1】:

    @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();
    }
    }
    

    【讨论】:

      【解决方案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

      【讨论】:

      • 嗨 sohilvassa,我看到你在 imageview 中显示来自 url 的图像。此图像是否会从 url 不断更新?请让我知道我能完成这项工作。谢谢回复
      猜你喜欢
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多