个人资料

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

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

分类:

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

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 70
为此篇作品打分
10
   评论