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

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

问题描述

这个问题的回答已经过去 4 年了,这篇博文.

It has been 4 years since this question has been answered with this blog post.

是否有标准方法可以使用来自 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天全站免登陆