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; } |