【问题标题】:What should I do to access camera in a UWP application using MediaCapture?我应该怎么做才能使用 MediaCapture 在 UWP 应用程序中访问相机?
【发布时间】:2017-06-29 12:24:40
【问题描述】:

我尝试在 UWP 应用程序中访问相机,但出现错误:

Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll
WinRT information: Access is denied.

The app was denied access to the camera
The thread 0x2c9c has exited with code 0 (0x0).
The program '[3352] CameraGetPreviewFrame.exe' has exited with code 1 (0x1).

这是我的代码:

if (cameraDevice == null)
{
    Debug.WriteLine("No camera device found!");
    return;
}

// Create MediaCapture and its settings
_mediaCapture = new MediaCapture();

// Register for a notification when something goes wrong
_mediaCapture.Failed += MediaCapture_Failed;

var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };

// Initialize MediaCapture
try
{
    await _mediaCapture.InitializeAsync(settings);
    _isInitialized = true;
}
catch (UnauthorizedAccessException)
{
    Debug.WriteLine("The app was denied access to the camera");
}

能否解释一下为什么会出现异常以及如何解决问题?

【问题讨论】:

    标签: c# uwp camera media


    【解决方案1】:

    您应该为您的项目设置麦克风和网络摄像头功能。为此,您可以按照以下步骤操作

    1. 打开 Package.appxmanifest
    2. 转到功能选项卡
    3. 检查麦克风网络摄像头

    【讨论】:

      猜你喜欢
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多