在Xamarin / C#中从URL加载的UIImage [英] UIImage loaded from URL in Xamarin / C#

查看:82
本文介绍了在Xamarin / C#中从URL加载的UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题回答<已经过去了4年a href =http://escoz.com/blog/displaying-web-images-with-monotouch---uiwebimageview/\"rel =nofollow noreferrer>此博文。

有没有一种标准方法可以使用URL中的图像创建UIImage?类似于:

Is there a standard way to create a UIImage with an image from a URL? Something like:

UIImage image = UIImage.FromFile("http://foo.com/bar.jpg");

我觉得我可能错过了一些非常简单的东西。

I feel like I'm probably missing something really simple.

推荐答案

不是单行,但只有很少的行,你可以自己滚动。例如

Not a one-liner, but with very few lines you can roll your own. E.g.

static UIImage FromUrl (string uri)
{
    using (var url = new NSUrl (uri))
    using (var data = NSData.FromUrl (url))
        return UIImage.LoadFromData (data);
}

来电,包括来自 UIImage的电话,是线程安全的。

The calls, including the one from UIImage, are thread-safe.

这篇关于在Xamarin / C#中从URL加载的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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