2

我正在尝试使用 Windows RT/XAML 开发模型创建一个可以将相机用于 Windows Phone 8.1 的应用程序。

当我尝试从 MediaCapture 类中调用任一捕获方法时,我会收到带有消息“参数不正确”的 ArgumentException。这是我的代码

    private async Task Initialize()
    {
        if (!DesignMode.DesignModeEnabled)
        {               
            await _mediaCaptureMgr.InitializeAsync();
            ViewFinder.Source = _mediaCaptureMgr;
            await _mediaCaptureMgr.StartPreviewAsync();
        }
    }

    private async void ViewFinder_OnTapped(object sender, TappedRoutedEventArgs e)
    {
        ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

        var stream = new InMemoryRandomAccessStream();

        await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);

        _bitmap = new WriteableBitmap((int) ViewFinder.ActualWidth, (int) ViewFinder.ActualHeight);
        stream.Seek(0);
        await _bitmap.SetSourceAsync(stream);

        PreviewImage.Source = _bitmap;
        PreviewElements.Visibility = Visibility.Visible;
        ViewFinder.Visibility = Visibility.Collapsed;
        Buttons.Visibility = Visibility.Visible;
        Message.Visibility = Visibility.Collapsed;

        stream.Seek(0);
        var buffer = new global::Windows.Storage.Streams.Buffer((uint) stream.Size);
        stream.ReadAsync(buffer, (uint) stream.Size, InputStreamOptions.None);

        DataContext = buffer.ToArray();
        if (PhotoCaptured != null)
            PhotoCaptured(this, null);
    }

在页面加载时调用初始化方法,当他们点击我在 xaml 中的 CaptureElement 时调用 viewfinder_ontapped。错误被抛出

await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);

真正奇怪的是,我下载了 winrt xaml 工具包的最新源代码http://winrtxamltoolkit.codeplex.com/并尝试了他们的示例相机应用程序,它使用了类似的代码。它在 MediaCapture.CapturePhotoToStorageFileAsync() 上引发相同的错误。谁能帮我找出原因?

4

0 回答 0