小编Joh*_*ang的帖子

如何将流转换为BitmapImage

这是我的代码

 private async void OnGetImage(object sender, RoutedEventArgs e)
        {
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    HttpResponseMessage response = await client.GetAsync(new Uri(txtUri.Text));

                    BitmapImage bitmap = new BitmapImage();

                    if (response != null && response.StatusCode == HttpStatusCode.OK)
                    {

                        using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                        {
                            await response.Content.WriteToStreamAsync(stream);
                            stream.Seek(0UL);
                            bitmap.SetSource(stream);
                        }
                        this.img.Source = bitmap;
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            }
        } 
Run Code Online (Sandbox Code Playgroud)

但现在我不能在uwp中使用WriteToStreamAsync(),谁可以帮助我?

c# uwp

0
推荐指数
1
解决办法
3576
查看次数

标签 统计

c# ×1

uwp ×1