UIImage loaded from URL in Xamarin / C#

前端 未结 5 982
情歌与酒
情歌与酒 2021-02-01 17:07

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

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

5条回答
  •  醉梦人生
    2021-02-01 17:55

    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);
    }
    

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

提交回复
热议问题