个人资料

跳过导航链接首页 > 博客列表 > 博客正文

UWP下载网络图片并保存在本地

:

UWP下载网络图片并保存在本地

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private async Task<StorageFile> LoadwebImage(string uriString)
{
    //var ImgFolder = KnownFolders.PicturesLibrary;
    var ImgFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    StorageFile SaveFile = await ImgFolder.CreateFileAsync($"{DateTime.Now.ToString("yyyy.MM.dd")}.jpg", CreationCollisionOption.OpenIfExists);
    using (Windows.Web.Http.HttpClient http = new Windows.Web.Http.HttpClient())
    {
        IBuffer buffer = await http.GetBufferAsync(new Uri(uriString));
        byte[] bytes = WindowsRuntimeBufferExtensions.ToArray(buffer, 0, (int)buffer.Length);
        using (Stream Fstream = await SaveFile.OpenStreamForWriteAsync())
        {
            await Fstream.WriteAsync(bytes, 0, bytes.Length);
        }
    }
    return SaveFile;
}

admin
最初发表2019/9/28 4:10:11 最近更新2019/9/28 4:10:11 1178
为此篇作品打分
10分
   评论