1

我正在尝试将图像从网络保存到本地存储以供以后操作,但它似乎已损坏并且尝试使用外部应用程序打开它失败。在网络浏览器中打开图像完全正常。谢谢你的帮助。

var client = new HttpClient();
var clientResponse = await client.GetByteArrayAsync(imageUri);

var temp = ApplicationData.Current.TemporaryFolder;
StorageFile file;
if ((await temp.GetFilesAsync()).Any(f => f.Name == "temp_image.png")) {
    file = await temp.GetFileAsync("tempcolorizer.png");
} else {
    file = await temp.CreateFileAsync("temp_image.png");
}
using (var fs = await file.OpenReadAsync())
using (var writer = new DataWriter(fs)) {
    writer.WriteBytes(clientResponse);
}
4

1 回答 1

1

你必须打电话StoreAsync

using (var fs = await file.OpenReadAsync())
using (var writer = new DataWriter(fs)) {
  writer.WriteBytes(clientResponse);
  await writer.StoreAsync();
}
于 2012-08-10T10:41:29.773 回答