如何使用Windows.Web.Http在Windows应用商店应用程序下载并存储来自互联网的jpeg图像?如何使用Windows.Web.Http下载和存储图像?
我面临的问题是,我不知道什么得到...异步和写...异步方法我必须使用图像?这与文件非常不同,而不是字符串。
只有Windows.Web.Http!
没有第三方解决方案!
如果您有其他建议,请使用评论部分,而不是答案。谢谢!
…
using Windows.Storage;
using Windows.Web.Http;
Uri uri = new Uri("http://image.tmdb.org/t/p/w300/" + posterPath);
HttpClient httpClient = new HttpClient();
// I guess I need to use one of the Get...Async methods?
var image = await httpClient.Get…Async(uri);
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFolder cachedPostersFolder = await localFolder.CreateFolderAsync("cached posters", CreationCollisionOption.OpenIfExists);
StorageFile posterFile = await cachedPostersFolder.CreateFileAsync(posterPath, CreationCollisionOption.ReplaceExisting);
// I guess I need to use one of the Write...Async methods?
await FileIO.Write…Async(posterFile, image);
为什么不使用[BackgroundDownloader(http://msdn.microsoft.com/library/windows相反,你可以使用GetStreamAsync的方式,我有/apps/windows.networking.backgroundtransfer.backgrounddownloader.aspx)? – 2014-11-02 23:32:00