C# 试图保存由FileOpenPicker选择并由FileSavePicker保存的图片的副本
这是迄今为止我拥有的打开图片并试图保存它的代码 任何关于它为什么不起作用的信息都将非常感谢C# 试图保存由FileOpenPicker选择并由FileSavePicker保存的图片的副本,c#,uwp,windows-store-apps,C#,Uwp,Windows Store Apps,这是迄今为止我拥有的打开图片并试图保存它的代码 任何关于它为什么不起作用的信息都将非常感谢 FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation =PickerLocationId.PicturesLibrary; openP
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation =PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation =
PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add("jpeg image", new List<string>()
{ ".jpg" });
savePicker.SuggestedFileName = "Photo";
string token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
StorageFile SaveFile = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(token);
StorageFile savefile = await savePicker.PickSaveFileAsync();
if (SaveFile != null)
{
await FileIO.WriteTextAsync(SaveFile, SaveFile.Name);
}
}
FileOpenPicker-openPicker=newfileopenpicker();
openPicker.ViewMode=PickerViewMode.缩略图;
openPicker.SuggestedStartLocation=PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(“.jpg”);
openPicker.FileTypeFilter.Add(“.jpeg”);
openPicker.FileTypeFilter.Add(“.png”);
StorageFile文件=等待openPicker.PickSingleFileAsync();
如果(文件!=null)
{
FileSavePicker savePicker=新FileSavePicker();
savePicker.SuggestedStartLocation=
PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add(“jpeg图像”,新列表()
{.jpg});
savePicker.SuggestedFileName=“Photo”;
string token=Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(文件);
StorageFile SaveFile=等待StorageApplicationPermissions.FutureAccessList.GetFileAsync(令牌);
StorageFile savefile=wait savePicker.PickSaveFileAsync();
if(SaveFile!=null)
{
等待FileIO.WriteTextAsync(SaveFile,SaveFile.Name);
}
}
将打开的文件存储到FutureAccessList
中,然后立即将其作为SaveFile
变量检索。就在下面,您创建了一个saveFile
,我想这是您想要使用的,但是在WriteTextAsync
方法中,您将saveFile
作为目标,而不是saveFile
您肯定应该改进您的命名约定,只有大小写不同的两个变量很容易出错。此外,局部变量应始终以小写字母开头。“为什么它不起作用”-您需要向我们提供有关该问题的更多信息。例如,您在保存时是否看到任何错误?或者,当您尝试保存文件时,应用程序是否停止响应?您有两个名为
SaveFile
和SaveFile
的StorageFile
。。。你想保存到哪一个?