自定义相机视图 UWP C#
Custom camera view UWP C#
如何制作自定义摄像头视图,例如 Messenger 应用程序所具有的视图?有可能拍照和使用闪光灯吗?
我尝试使用 UWP 示例,但找不到
合适的解决方案。
对于布局部分,您可以例如这样编写代码:
<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>
With possibility of making photos and using flash?
拍照和视频部分,可以参考官方Basic camera app sample,将代码集成到你的示例中,然后在[=16=的Tapped
和Holding
事件中]:
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;
我不知道相机符号是做什么用的,所以我假设你想要 enable/disable 闪光灯,例如这样:
private void SymbolIcon_Tapped(object sender, TappedRoutedEventArgs e)
{
_mediaCapture.VideoDeviceController.FlashControl.Enabled = !_mediaCapture.VideoDeviceController.FlashControl.Enabled;
}
而且我认为您可能还需要在点击控件时自定义布局,或者在录制视频和旋转布局时等等...
如何制作自定义摄像头视图,例如 Messenger 应用程序所具有的视图?有可能拍照和使用闪光灯吗?
我尝试使用 UWP 示例,但找不到
合适的解决方案。
对于布局部分,您可以例如这样编写代码:
<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>
With possibility of making photos and using flash?
拍照和视频部分,可以参考官方Basic camera app sample,将代码集成到你的示例中,然后在[=16=的Tapped
和Holding
事件中]:
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;
我不知道相机符号是做什么用的,所以我假设你想要 enable/disable 闪光灯,例如这样:
private void SymbolIcon_Tapped(object sender, TappedRoutedEventArgs e)
{
_mediaCapture.VideoDeviceController.FlashControl.Enabled = !_mediaCapture.VideoDeviceController.FlashControl.Enabled;
}
而且我认为您可能还需要在点击控件时自定义布局,或者在录制视频和旋转布局时等等...