我想知道如何在Windows通用应用程序中设置相机分辨率为16; 9 宽高比,我尝试了不同的代码,但它们都没有工作,我也失去了一点帧速率当我使用下面的一些代码时,我不知道如何将摄像头分辨率设置为16; 9 这是一个问题, VideoeEcodingProporties 内部是否有任何功能可以帮助我要做到这一点。
XAML UWP CODE;
<Page
x:Class="whatchado_recorder.Video.Capture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:whatchado_recorder"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
SizeChanged="Page_SizeChanged">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel x:Name="CaptureStack" Visibility="Collapsed" Margin="0,12,0,0" HorizontalAlignment="Stretch" MaxWidth="720">
<ProgressBar x:Name="RecordProgress" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="6" Minimum="0" Maximum="90"/>
<TextBlock x:Name="CameraErrorTextBlock" x:Uid="NoCameraFound" Margin="0,120,0,24" HorizontalAlignment="Center" Text="No camera found :(" VerticalAlignment="Center" FontSize="24" Visibility="Collapsed"/>
<Grid x:Name="CaptureGrid" Margin="0,12,0,0">
<CaptureElement x:Name="CaptureElement" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="360" Tapped="captureElement_Tapped"/>
<Border Background="Black" Padding="6" Opacity="0.5" HorizontalAlignment="Center" VerticalAlignment="Top">
<TextBlock Foreground="White" FontSize="12">
<Run x:Uid="MaxTime" Text="Max. Time: "/>
<Run Text="{Binding Path=Args.SelectedQuestionOnRecordStart.MaxVideoLength, Converter={StaticResource DoubleToStringConverter}}"/>
</TextBlock>
</Border>
<local:MouseOver x:Name="BackgroundCircle" HorizontalAlignment="Center" VerticalAlignment="Center">
<local:MouseOver.NormalState>
<Ellipse Fill="Black" Opacity="0.25" HorizontalAlignment="Center" VerticalAlignment="Center" Width="192" Height="192" Tapped="captureElement_Tapped"/>
</local:MouseOver.NormalState>
<local:MouseOver.MouseOverState>
<Ellipse Fill="Black" Opacity="0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Width="192" Height="192" Tapped="captureElement_Tapped"/>
</local:MouseOver.MouseOverState>
</local:MouseOver>
<Ellipse x:Name="RecordCircle" Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="36" Height="36" Tapped="captureElement_Tapped"/>
<local:MouseOver x:Name="BackgroundStopCircle" Visibility="Collapsed" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,24">
<local:MouseOver.NormalState>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="64" Height="64">
<Ellipse Fill="Black" Opacity="0.25" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="captureElement_Tapped"/>
<Rectangle Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" Tapped="captureElement_Tapped"/>
</Grid>
</local:MouseOver.NormalState>
<local:MouseOver.MouseOverState>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="64" Height="64">
<Ellipse Fill="Black" Opacity="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="captureElement_Tapped"/>
<Rectangle Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" Tapped="captureElement_Tapped"/>
</Grid>
</local:MouseOver.MouseOverState>
</local:MouseOver>
<TextBlock x:Name="CountdownText" Visibility="Collapsed" Foreground="White" FontSize="72" Margin="0, -48, 0, 0" Text="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock x:Name="ExplanationText" x:Uid="LookIntoCamera" Visibility="Collapsed" Foreground="White" FontSize="12" Margin="0, 48, 0, 0" Text="Look into the camera" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Button x:Name="CancelButton" x:Uid="Cancel" Content="Cancel" Style="{StaticResource NormalButtonStyle}" Margin="0,12,0,0" Padding="24,0,24,0" HorizontalAlignment="Right" Click="cancelButton_Click"/>
</StackPanel>
</Grid>
</Page>
UWP CS.CODE;
var maxPreviewResolution = mc.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Height > (i2 as VideoEncodingProperties).Height ? i1 : i2);
await mc.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, maxPreviewResolution);
`
答案 0 :(得分:0)
请参阅:
IEnumerable<StreamResolution> allPreviewProperties = _previewer.MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => new StreamResolution(x));
获得mediaStream属性后,您可以查找
的位置width/16 == height/9
查找符合您比例的所有分辨率