从URL将Image设置为ImageView [英] Set Image to a ImageView from URL

查看:153
本文介绍了从URL将Image设置为ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Imageview和互联网上图片的链接。我把这张照片设置为像这样的ImageView,

I have Imageview and a link to the picture on the Internet. I set this picture to the ImageView like this,

public ImageView iv;
iv = (ImageView) findViewById(R.id.imageView);
String img = "https://www.google.com/images/srpr/logo11w.png";
iv.setImageDrawable(Drawable.createFromPath(img));

我想要做的是从互联网上下载图片到我的Android应用程序并将其应用于ImageView的。我希望尽可能简单。

What I want to do is download a picture from the internet to my android application and apply it to an ImageView. I want to make it as easy as possible.

帮助我

String img_url= //url of the image
    URL url=new URL(img_url);
    Bitmap bmp; 
    bmp=BitmapFactory.decodeStream(url.openConnection().getInputStream());
    ImageView iv=(ImageView)findviewById(R.id.imageview);
    iv.setImageBitmap(bmp);


推荐答案

有很多lib这样做,我最喜欢的是< a href =http://square.github.io/picasso/ =noreferrer> Picasso 。

There many libs to do this, my favourite is Picasso.

这是一个用法示例:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

试一试:)

这篇关于从URL将Image设置为ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆