Access denied while saving image in UWP.Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

巧了我就是萌 提交于 2019-12-02 01:46:56

Try to access the file by the stream, not the path:

var photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("image2.jpg", CreationCollisionOption.ReplaceExisting);

if (photofile != null)
{
    using (var stream = await photofile.OpenAsync(FileAccessMode.ReadWrite))
    {
        await offscreen.SaveAsync(stream, CanvasBitmapFileFormat.Jpeg);
    }
}

In UWP if you access files via path, you will likely get Access Denied in many cases, it should be done via StorageFile.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!