加载远程图像图像、加载

由网友(卖樱桃的小丸子)分享简介:在Android中,什么是最简单的方法如下:从远程服务器加载图像。 在显示它的ImageView的。解决方案 请参阅ImageView.setImageURI.是这样的:myImageView.setImageURI(Uri.parse(http://example.com/logo.png));和你就大功告成了。编...

在Android中,什么是最简单的方法如下:

从远程服务器加载图像。 在显示它的ImageView的。 解决方案

请参阅ImageView.setImageURI.是这样的:

  myImageView.setImageURI(Uri.parse(http://example.com/logo.png));
 

和你就大功告成了。

编辑:我没有测试过上面的方法,并从评论,似乎这是行不通的。这里是另一种方法,我在应用程序中实际使用的,我知道它的工作原理:

 尝试{
    URL thumb_u =新的URL(http://www.example.com/image.jpg);
    抽拉thumb_d = Drawable.createFromStream(thumb_u.openStream(),SRC);
    myImageView.setImageDrawable(thumb_d);
}
赶上(例外五){
    // 处理它
}
 
WinForm加载网络图片并显示进度条

我不知道的第二个参数 Drawable.createFromStream 是的,但通过SRC似乎工作。如果有谁知道,请闪耀光芒,作为文档真的不说什么。

In Android, what is the simplest approach to the following:

Load an image from a remote server. Display it in an ImageView.

解决方案

See ImageView.setImageURI. Something like:

myImageView.setImageURI(Uri.parse("http://example.com/logo.png"));

And you're done.

Edit: I have not tested the above method and, from the comments, it seems it doesn't work. Here's another method that I actually used in an application and I know it works:

try {
    URL thumb_u = new URL("http://www.example.com/image.jpg");
    Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
    myImageView.setImageDrawable(thumb_d);
}
catch (Exception e) {
    // handle it
}

I have no idea what the second parameter to Drawable.createFromStream is, but passing "src" seems to work. If anyone knows, please shed some light, as the docs don't really say anything about it.

阅读全文

相关推荐

最新文章