【发布时间】:2018-08-21 16:28:21
【问题描述】:
我做了一个简单的 UWP 应用来测试一些代码
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
FlipButton.Click += new RoutedEventHandler(FlipButton_Click);
}
private async void FlipButton_Click(object sender, RoutedEventArgs e)
{
var sf = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///test_pattern.png"));
var original = await sf.OpenStreamForReadAsync();
using (var stream = new SKManagedStream(original))
using (var bitmap = SKBitmap.Decode(stream))
{
ITransform flip = new Flip(FlipOrientation.Vertical);
SKBitmap result = flip.Perform(bitmap);
StorageFolder storageFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.PicturesLibrary);
StorageFile flipfile = await storageFolder.CreateFileAsync("flip_vertical.png", CreationCollisionOption.ReplaceExisting);
Stream flipstream = await flipfile.OpenStreamForWriteAsync();
using (SKManagedWStream wstream = new SKManagedWStream(flipstream))
{
result.Encode(wstream, SKEncodedImageFormat.Png, 100);
}
}
}
}
它在StorageFolder 行抛出UnauthorizedAccessException。我是 UWP 的新手,我不知道如何使它工作......
PS。我使用的一些代码来自 github 上的 Microsoft Samples...
【问题讨论】:
-
不要使用
...ForUserAPI,并以用户身份传递null。相反,只需使用非...ForUserAPI(或实际传入真实用户的对象)。通过null不太可能有好的结局。
标签: c# exception io uwp storage