2

我正在尝试制作一个简单的网络摄像头应用程序:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.MediaProperties;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

namespace App1
{
public sealed partial class MainPage : Page
{
    private Windows.Media.Capture.MediaCapture m_mediaCaptureMgr;
    private Windows.Storage.StorageFile m_photoStorageFile;
    private readonly String PHOTO_FILE_NAME = "photo.jpg";

    public MainPage()
    {
        this.InitializeComponent();
    }


    internal async void initializeCamera()
    {
        m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
        await m_mediaCaptureMgr.InitializeAsync();
        statusBox.Text = "initialized";
    }
    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }

    internal async void takePicture(object sender, RoutedEventArgs e)
    {

        m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
        ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
        await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile);
    }

    private void initializeButton(object sender, RoutedEventArgs e)
    {
        initializeCamera();
    }
}

}

但是,当我单击 initializeButton 时,出现异常:

UnauthorizedAccessException (Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)))

这里可能是什么问题?

编辑:我发现了这个错误。基本上,如果网络摄像头已经初始化,再次尝试初始化它会触发异常。所以我不得不放一个标志,然后一些尝试/捕捉

4

2 回答 2

1

您是否在清单文件中设置了麦克风和网络摄像头的功能?

于 2012-11-13T07:57:41.540 回答
0

Package.Appmnifest在文件中查看麦克风和网络摄像头功能

在此处输入图像描述

于 2012-11-13T09:29:11.147 回答