UIImage loaded from URL in Xamarin / C#

前端 未结 5 977
情歌与酒
情歌与酒 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:38

    Below code should work,

    public static async Task LoadImage(string imageUrl)
    {
                var httpClient = new HttpClient();
    
                var contents = await httpClient.GetByteArrayAsync(imageUrl);
                return UIImage.LoadFromData(NSData.FromArray(contents));
    }
    

提交回复
热议问题