diff --git a/src/WinUIEx/CaptureElement.Rendering.cs b/src/WinUIEx/CaptureElement.Rendering.cs index c9845bf..f37627e 100644 --- a/src/WinUIEx/CaptureElement.Rendering.cs +++ b/src/WinUIEx/CaptureElement.Rendering.cs @@ -28,6 +28,8 @@ namespace WinUIEx // https://learn.microsoft.com/en-us/windows/win32/api/mfidl/nn-mfidl-imfmediasink // https://github.com/nickluo/CameraCapture/ // https://github.com/castorix/WinUI3_DirectShow_Capture + // https://github.com/TripleSM/MediaFrameCapture/blob/main/WinUI3MediaFrameCapture/WinUI3MediaFrameCapture/MainWindow.xaml.cs - Framereader, not sink based + // https://github.com/mmaitre314/MediaCaptureWPF/blob/6b42e0c288c3ef290b47f1267b37ac7488f60483/MediaCaptureWPF/CapturePreview.cs#L41 public partial class CaptureElement { private static readonly Guid IID_IDXGIFactory2_Guid = new Guid("50c83a1c-e072-4c48-87b0-3630fa36a6d0"); diff --git a/src/WinUIExSample/Pages/Home.xaml.cs b/src/WinUIExSample/Pages/Home.xaml.cs index e66bebd..45e3539 100644 --- a/src/WinUIExSample/Pages/Home.xaml.cs +++ b/src/WinUIExSample/Pages/Home.xaml.cs @@ -37,9 +37,18 @@ private async void LoadWebcam() { var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); DeviceInformation cameraDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front) ?? allVideoDevices.FirstOrDefault(); - + + var frameSourceGroups = await Windows.Media.Capture.Frames.MediaFrameSourceGroup.FindAllAsync(); + var selectedFrameSourceGroup = frameSourceGroups.First(); mediaCapture = new Windows.Media.Capture.MediaCapture(); - var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; + var settings = new MediaCaptureInitializationSettings + { + VideoDeviceId = cameraDevice.Id, + SourceGroup = selectedFrameSourceGroup, + SharingMode = MediaCaptureSharingMode.SharedReadOnly, + StreamingCaptureMode = StreamingCaptureMode.Video, + MemoryPreference = MediaCaptureMemoryPreference.Cpu + }; await mediaCapture.InitializeAsync(settings); elm.Source = mediaCapture; //await mediaCapture.StartPreviewAsync();