2010-10-11 57 views

回答

1

我已经写了从图像URL创建一个Drawable的功能,下面看:

private Drawable downloadThumbnails(String url) { 
    Drawable d = null; 
    try { 
     InputStream is = (InputStream) this.fetch(url); 
     d = Drawable.createFromStream(is, "src_from_stream"); 
     return d; 
    } catch (MalformedURLException e) { 
    } catch (IOException e) { 
    } 
    return null; 
} 

public Object fetch(String address) throws MalformedURLException, IOException { 
    URL url = new URL(address); 
    Object content = url.getContent(); 
    return content; 
} 

然后使用它是这样的:

Drawable img = downloadThumbnails("http://yoururl.com/image.png"); 
yourImageView.setImageDrawable(img); 
0

我强烈建议使用Picasso

Picasso.with(context).load("http://an.url.com/lovely_cats.png").into(imageView); 

它有很多有用的功能,可以让你:

  • 裁剪图像
  • 调整图像大小
  • 旋转图像
  • 将图片处理为目标视图
  • 更换不会下载与当地占位文件

更加 - 主要在一条线上(或呼叫)。

相关问题