我想把我的后置摄像头分成两个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();
}
}
GamePage.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>
答案 0 :(得分:0)
我不认为MediaCapture同时支持流式传输到多个CaptureElements。推荐这个作为解决方法有点痛苦,但理论上你可以在计时器中使用GetPreviewFrameAsync
方法,并手动将这些帧渲染到Image控件。 a sample显示了如何使用API。我希望这会增加内存和CPU使用率,而不仅仅是渲染单个预览。