簡體   English   中英

如何在Windows 10通用APP中設置相機分辨率縱橫比16; 9

[英]How to set a Camera Resolution Aspect Ratio 16;9 in Windows 10 Universal APP

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

您可以看一下相機分辨率示例

看到:

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

一旦有了mediaStream屬性,就可以在哪里尋找

width/16 == height/9

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM