我想将我的后置摄像头拆分为两个 ui 对象,例如镜头。但是当我启动应用程序时出现错误。这是它:
如何将相机分成两个对象?这是我的代码: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/