2016-08-23 125 views
0

如何使像Messenger应用程序一样自定义摄像头视图?有可能制作照片和使用闪光灯?自定义摄像头视图UWP C#

Messenger app camera

我已经尝试使用UWP样,但我无法找到一个
合适的解决方案。

+1

您可以创建自定义控件,该控件具有用于预览的CaptureElement控件,并且可以使用MediaCapture API捕捉照片和其他与媒体相关的任务。 –

回答

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,代码然后集成到你的样品中的BorderTappedHolding事件:

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; 

我不知道什么是相机符号,所以我假设你想要启用/禁用fl灰例如像这样:

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

我想你可能还需要自定义布局时,控制被窃听,或者当被记录和布局的旋转视频,等等...