c# - 如何在 Windows 10 Mobile 上分屏摄像头

标签 c# xaml windows-10-mobile

我想将我的后置摄像头拆分为两个 ui 对象,例如镜头。但是当我启动应用程序时出现错误。这是它:

enter image description here

如何将相机分成两个对象?这是我的代码:GamePage.xaml.cs

 public sealed partial class GamePage : Page
{
    readonly Game1 _game;

    public GamePage()
    {
        this.InitializeComponent();
        // Create the game.
       // var launchArguments = string.Empty;
        //_game = MonoGame.Framework.XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
    }

    Windows.Media.Capture.MediaCapture captureManager;
    async private Task Start_Capture_Preview_Click()
    {
        captureManager = new MediaCapture();    //Define MediaCapture object  
        await captureManager.InitializeAsync();   //Initialize MediaCapture and   
        capturePreview.Source = captureManager;   //Start preiving on CaptureElement  
        capturePreview2.Source = captureManager;   //Start preiving on CaptureElement  
        await captureManager.StartPreviewAsync();  //Start camera capturing   
    }
    async private void Stop_Capture_Preview_Click()
    {
        await captureManager.StopPreviewAsync();  //stop camera capturing  

    }

    async private Task Start_Capture_Preview_ClickR()
    {
        captureManager = new MediaCapture();    //Define MediaCapture object  
        await captureManager.InitializeAsync();   //Initialize MediaCapture and   
        capturePreview2.Source = captureManager;   //Start preiving on CaptureElement  
        await captureManager.StartPreviewAsync();  //Start camera capturing   
    }


    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        await Start_Capture_Preview_Click();
        await Start_Capture_Preview_ClickR();
    }

}

游戏页面.xaml:

<Page
x:Class="Victoria_XVR.GamePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Victoria_XVR"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid x:Name="xD">
    <Grid.RowDefinitions>
        <RowDefinition Height="200" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="300" />
        <ColumnDefinition Width="300" />
    </Grid.ColumnDefinitions>

    <CaptureElement x:Name="capturePreview" Grid.Row="0" Grid.Column="0"/>
    <CaptureElement x:Name="capturePreview2" Grid.Row="0" Grid.Column="1"/>
</Grid>

最佳答案

我认为 MediaCapture 不支持同时流式传输到多个 CaptureElements。将此作为解决方法推荐有点痛苦,但理论上您可以在计时器中使用 GetPreviewFrameAsync 方法,并手动将这些帧呈现给 Image 控件。有 a sample展示了如何使用 API。我预计这会增加内存和 CPU 使用率,而不是只渲染单个预览。

关于c# - 如何在 Windows 10 Mobile 上分屏摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36225522/

相关文章:

c# - 从另一个类(在另一个线程上)写在文本框中

c# - 在特定屏幕上启动进程

c# - MVC Entity Framework 中的种子方法

WPF 内联样式未设置模板值

javascript - 窗口中的“ontouchstart”在 MS Edge 浏览器手机模拟器中返回 true,但未触发 touchstart 事件

c# - _Layout.cshtml 上的 MVC 决策

c# - 绑定(bind) EasingColorKeyframe 值

webview - 我们可以使用 WebView 在 UWP 应用中显示远程 Web 内容吗?

windows-10 - 如何在通用Windows平台(Windows 10)中使用共享项目?

xaml - 如何在 WinRT 中为页面导航转换设置动画?