如何在 Windows 16 通用应用程序中设置相机分辨率纵横比 10;9

本文关键字:分辨率 相机 设置 Windows 应用程序 | 更新日期: 2023-09-27 18:37:10

我想知道如何在 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>

威斯康星大学。法典;

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);
                        `

如何在 Windows 16 通用应用程序中设置相机分辨率纵横比 10;9

您可以查看相机分辨率示例

看:

IEnumerable<StreamResolution> allPreviewProperties = _previewer.MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => new StreamResolution(x));

拥有mediaStream属性后,您可以查找位置

width/16 == height/9

查找与您的比例匹配的所有分辨率