自定义相机视图UWP C#

时间:2016-08-23 09:35:05

标签: c# camera uwp custom-view

如何制作自定义相机视图,例如Messenger应用程序?有可能制作照片和使用闪光灯吗?

Messenger app camera

我试图使用UWP样本,但我找不到 合适的解决方案。

1 个答案:

答案 0 :(得分:1)

对于布局部分,您可以使用例如以下代码:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <CaptureElement Name="PreviewControl" Stretch="Uniform" />
    <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
                Orientation="Vertical" Background="Transparent" Padding="10,10">
        <TextBlock Text="Hold for Video, tap for photo" FontSize="15" Foreground="White"
                   HorizontalAlignment="Center" />
        <Grid Margin="0,5,0,0" Background="#7FD3D3D3" Padding="10,10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Text="Cancel" FontSize="15" Foreground="White" Margin="10,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" />
            <Border Height="50" Width="50" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"
                    CornerRadius="25" BorderBrush="White" BorderThickness="2" Tapped="Border_Tapped" Holding="Border_Holding">
                <Ellipse Width="40" Height="40" Fill="White" />
            </Border>
            <SymbolIcon Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0" Symbol="Camera" Foreground="White"
                        Tapped="SymbolIcon_Tapped" />
        </Grid>
    </StackPanel>
</Grid>
  

有可能制作照片和使用闪光灯吗?

要拍摄照片和视频,您可以参考官方Basic camera app sample,将代码整合到您的示例中,然后在TappedHolding Border事件中进行整合:

private async void Border_Tapped(object sender, TappedRoutedEventArgs e)
{
    await TakePhotoAsync();
}

private async void Border_Holding(object sender, HoldingRoutedEventArgs e)
{
    await StartRecordingAsync();
}

要启用相机闪光灯,您可以设置:

_mediaCapture.VideoDeviceController.FlashControl.Enabled = true; 

我不知道相机符号是什么,所以我假设您要启用/禁用闪光灯,例如:

private void SymbolIcon_Tapped(object sender, TappedRoutedEventArgs e)
{
    _mediaCapture.VideoDeviceController.FlashControl.Enabled = !_mediaCapture.VideoDeviceController.FlashControl.Enabled;
}

我认为您可能还需要在点击控件时,或者在录制视频和旋转布局时自定义布局等等...