如何从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.