尝试保存由 FileOpenPicker 选择并由 FileSavePicker 保存的图片的副本

Trying to save a copy of a picture selected by FileOpenPicker and saved by FileSavePicker

这是我目前打开图片并尝试保存它的代码 任何有关为什么它不起作用的信息都将非常感谢。

        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);
            }

        }

您将打开的文件存储到 FutureAccessList 中,然后立即将其作为 SaveFile 变量检索。在下面你创建了一个 saveFile ,我想这是你想要使用的,但是在 WriteTextAsync 方法中你传递 SaveFile 作为目标,而不是 saveFile.

你绝对应该改进你的命名约定,让两个变量只在大小写上不同是很容易出错的。此外,局部变量应始终以小写字母开头。