如何从URL中的机器人获得的图像 [英] how to get Image from url in android

查看:194
本文介绍了如何从URL中的机器人获得的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望把图像在屏幕上而不是从绘制,图像应来自URL。

I want to put image on screen but not from drawable, image should comes from url.

code是这里

<ImageView android:id="@+id/ImageView01" android:src = "http://l.yimg.com/a/i/us/we/52/21.gif"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>

但它给错误在编译时

but it gives error at compile time

推荐答案

您可以直接显示来自Web图像而无需下载。请检查下面的功能。它会显示来自网络的图片到你的图像视图。

You can directly show image from web without downloading it. Please check the below function . It will show the images from the web into your image view.

public static Drawable LoadImageFromWebOperations(String url) {
    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    } catch (Exception e) {
        return null;
    }
}

然后设置图像的ImageView使用您的活动code。

then set image to imageview using code in your activity.

这篇关于如何从URL中的机器人获得的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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