Download an image to local storage in Metro style apps

前端 未结 5 1229
一向
一向 2020-12-16 07:22

In WinRT / C#, How do I download an image to a local folder to support caching of an online catalogue for offline use? is there a way to directly download the images and lin

5条回答
  •  温柔的废话
    2020-12-16 07:33

    GetResponseAsync will give you a WebResponse file not the image:

    Stream imageStream = downloadedimage.GetResponseStream();
    

    Then you can write to the image file:

    byte[] imageData = new byte[imageStream.Length];
    using(StreamReader reader = new Streamreader(imageStream))
    {
        reader.ReadBytes(imageData, 0, imageData.Length);
    }
    await FileIO.WriteBytesAsync(imgfile, imageData);
    

提交回复
热议问题