【发布时间】:2014-11-02 22:15:49
【问题描述】:
如何使用 Windows.Web.Http 从 Internet 下载 jpeg 图像并将其存储在 Windows Store 应用程序中?
我面临的问题是我不知道我必须对图像使用什么 Get...Async 和 Write...Async 方法?文件与字符串有很大不同。
仅限 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?
标签: c# windows-phone-8 windows-8 windows-store-apps windows-phone-8.1