No video is shown when the camera starts and calling the TakeSnapshot method results in an exception in PresentationCore.CriticalFromVisual, with the message "parameter v cannot be null'.
I've provided a simple test app that reproduces the problem. Platform is Windows 10, and the app is a .NET 5.0 WPF app using the latest Telerik UI for WPF nuget package. I have tried AnyCPU, x64 and x86 and the behavior is the same for all configurations, both release and debug.
I have tested on a desktop machine with a Logitech 910 webcam and on a Surface Pro 3 using the internal camera. The identical code works fine on WPF .NET Framework 4.7.2 on both devices.
Project file is attached.
Here is the window xaml:
<Window x:Class="cameratest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:cameratest"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Width="80"
Margin="4"
HorizontalAlignment="Left"
Click="OnSnapClick">Snap</Button>
<telerik:RadWebCam Grid.Row="1"
x:Name="radWebCam" />
</Grid>
</Window>
And the code behind:
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls;
using Telerik.Windows.MediaFoundation;
namespace cameratest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
radWebCam.SnapshotTaken += RadWebCamOnSnapshotTaken;
radWebCam.CameraError += RadWebCamOnCameraError;
}
private void RadWebCamOnCameraError(object sender, CameraErrorEventArgs e)
{
Debug.WriteLine(e.Error.Message);
}
private void RadWebCamOnSnapshotTaken(object sender, SnapshotTakenEventArgs e)
{
BitmapSource snapshot = e.Snapshot;
}
private void OnSnapClick(object sender, RoutedEventArgs e)
{
radWebCam.TakeSnapshot();
}
}
}
Modifying the app to disable auto start and initialize and state the camera manually results in the same problem.