0

我的 LocalFolder 中有一个图像文件,当在应用程序中单击按钮时会下载该文件。

我需要使用 FileSavePicker 将所述图像从 LocalFolder 移动到用户选择的另一个文件夹,例如桌面。

图像在 LocalFolder 中,我用来保存它的代码是:

var imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
         "image.png", CreationCollisionOption.ReplaceExisting);
var fs = await imageFile.OpenAsync(FileAccessMode.ReadWrite);
DataWriter writer = new DataWriter(fs.GetOutputStreamAt(0));
writer.WriteBytes(await response.Content.ReadAsByteArrayAsync());
await writer.StoreAsync();
writer.DetachStream();
await fs.FlushAsync();

我保存的当前代码(不完整)是:

FileSavePicker saver = new FileSavePicker();
saver.SuggestedStartLocation = PickerLocationId.Desktop;
saver.SuggestedFileName = "image.png";
StorageFile file = await saver.PickSaveFileAsync();

谁能告诉我如何执行此操作?

4

1 回答 1

1

您应该利用FileIO它来编写数据,因为它并不复杂。

var data = await response.Content.ReadAsByteArrayAsync();
var localFolder = ApplicationData.Current.LocalFolder;

var imageFile = await localFolder.CreateFileAsync(
         "image.png", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(imageFile, data).AsTask();
于 2013-05-01T17:36:00.207 回答