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

前端 未结 1 1896
时光取名叫无心
时光取名叫无心 2021-01-21 18:16

I am working on universal windows app on Windows 10 SDK to draw rectangle on faces recognized in the image.

I am using Win2D to edit the pictures and draw rectangle on i

相关标签:
1条回答
  • 2021-01-21 18:39

    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.

    0 讨论(0)
提交回复
热议问题