-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
2639 lines (2360 loc) · 147 KB
/
MainWindow.xaml.cs
File metadata and controls
2639 lines (2360 loc) · 147 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using GlobalStructures;
using static GlobalStructures.GlobalTools;
using Direct2D;
using static Direct2D.D2DTools;
using DXGI;
using static DXGI.DXGITools;
using WIC;
using static WIC.WICTools;
using D3D11;
using Windows.Devices.Enumeration;
using Windows.Media.Devices;
using Windows.Media.Capture;
using Windows.Media.Capture.Frames;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using Windows.Graphics.Imaging;
using WinRT;
using System.Threading;
using Windows.Storage.Streams;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
using Windows.Media.MediaProperties;
using Windows.Media;
using Windows.Media.Effects;
using Microsoft.UI;
using Microsoft.UI.Input;
using Microsoft.WindowsAppSDK.Runtime.Packages;
using System.Text;
using Windows.Graphics.DirectX.Direct3D11;
using Windows.Management.Deployment;
using Microsoft.WindowsAppSDK.Runtime;
using Windows.ApplicationModel;
using Windows.Media.Core;
using Windows.Media.FaceAnalysis;
using VideoEffectComponent;
using Windows.Devices.HumanInterfaceDevice;
using Windows.Devices.I2c;
using ABI.Windows.Foundation;
// References :
// https://github.com/microsoft/windows-universal-samples/tree/main/Samples/CameraFrames
// https://github.com/microsoft/Windows-Camera/tree/1b890286ce6a1e61edd3b92e7027353b0ac6c926/Samples/MediaCaptureWinUI3/MediaCaptureWinUI3
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace WinUI3_SwapChainPanel_MediaCapture
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
[ComImport]
[Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDirect3DDxgiInterfaceAccess
{
HRESULT GetInterface([MarshalAs(UnmanagedType.LPStruct)] Guid iid, out IntPtr ppv);
}
[ComImport]
[Guid("5B0D3235-4DBA-4D44-865E-8F1D0E4FD04D")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMemoryBufferByteAccess
{
void GetBuffer(out IntPtr buffer, out uint capacity);
}
ID2D1Factory m_pD2DFactory = null;
ID2D1Factory1 m_pD2DFactory1 = null;
IWICImagingFactory m_pWICImagingFactory = null;
IWICImagingFactory2 m_pWICImagingFactory2 = null;
IntPtr m_pD3D11DevicePtr = IntPtr.Zero; // Used in CreateSwapChain
Direct2D.ID3D11DeviceContext m_pD3D11DeviceContext = null; // Released in Clean : not used
IDXGIDevice1 m_pDXGIDevice = null;
ID2D1DeviceContext m_pD2DDeviceContext = null;
ID2D1DeviceContext5 m_pD2DDeviceContext5 = null;
IDXGISwapChain1 m_pDXGISwapChain1 = null;
ID2D1Bitmap1 m_pD2DTargetBitmap = null;
ID2D1SolidColorBrush m_pD2DMainBrush = null;
ID2D1SolidColorBrush m_pD2DSolidColorBrushPink = null;
ID2D1Bitmap1 m_pD2DBitmap1 = null;
private IntPtr hWndMain = IntPtr.Zero;
private Microsoft.UI.Windowing.AppWindow _apw;
private DeviceInformationCollection m_deviceList;
System.Collections.ObjectModel.ObservableCollection<ComboBoxItem> devices = new System.Collections.ObjectModel.ObservableCollection<ComboBoxItem>();
private MediaCapture m_MediaCapture = null;
private MediaFrameSource m_frameSource = null;
private MediaFrameFormat m_currentFrameFormat = null;
private MediaFrameReader m_FrameReader = null;
private bool m_bPreviewing = false;
private bool m_bRecording = false;
MediaMirroringOptions m_Mirror = MediaMirroringOptions.None;
MediaRotation m_Rotation = MediaRotation.None;
public ObservableCollection<MediaFrameFormatWrapper> MediaFormats { get; set; } = new ObservableCollection<MediaFrameFormatWrapper>();
public Windows.Media.Playback.MediaPlayer m_MP = new Windows.Media.Playback.MediaPlayer();
public MainWindow()
{
this.InitializeComponent();
hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
Microsoft.UI.WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWndMain);
_apw = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId);
_apw.MoveAndResize(new Windows.Graphics.RectInt32(400, 200, 1100, 800));
this.Title = "WinUI 3 : MediaCapture with SwapChainPanel";
Application.Current.Resources["ButtonBackgroundPointerOver"] = new SolidColorBrush(Microsoft.UI.Colors.LightSteelBlue);
Application.Current.Resources["ButtonBackgroundPressed"] = new SolidColorBrush(Microsoft.UI.Colors.MidnightBlue);
m_pWICImagingFactory = (IWICImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(WICTools.CLSID_WICImagingFactory));
m_pWICImagingFactory2 = (IWICImagingFactory2)m_pWICImagingFactory;
HRESULT hr = CreateD2D1Factory();
if (SUCCEEDED(hr))
{
hr = CreateDeviceContext();
hr = CreateDeviceResources();
hr = CreateSwapChain(IntPtr.Zero);
if (SUCCEEDED(hr))
{
hr = ConfigureSwapChain(hWndMain);
ISwapChainPanelNative panelNative = WinRT.CastExtensions.As<ISwapChainPanelNative>(scp1);
hr = panelNative.SetSwapChain(m_pDXGISwapChain1);
scp1.SizeChanged += scp1_SizeChanged;
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
}
this.Closed += MainWindow_Closed;
FillDevices();
LoadOverlayImage();
ChangeCursor(imgOverlay, Microsoft.UI.Input.InputSystemCursor.Create(Microsoft.UI.Input.InputSystemCursorShape.Hand));
//imgOverlay.Tapped += ImgOverlay_Tapped;
ChangeCursor(rectVignetteColor, Microsoft.UI.Input.InputSystemCursor.Create(Microsoft.UI.Input.InputSystemCursorShape.Hand));
LoadMP3("Assets\\Camera_Click.mp3");
}
private async void LoadMP3(string sRelativePath)
{
string sAbsolutePath = Path.Combine(AppContext.BaseDirectory, sRelativePath);
StorageFile sfFile = await StorageFile.GetFileFromPathAsync(sAbsolutePath);
m_MP.Source = Windows.Media.Core.MediaSource.CreateFromStorageFile(sfFile);
}
private void ChangeCursor(UIElement control, Microsoft.UI.Input.InputCursor cursor)
{
var cursorProperty = typeof(UIElement).GetProperty("ProtectedCursor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var currentCursor = cursorProperty?.GetValue(control) as InputSystemCursor;
Microsoft.UI.Input.InputCursor ic = cursor;
var methodInfo = typeof(UIElement).GetMethod("set_ProtectedCursor", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (methodInfo != null)
{
methodInfo.Invoke(control, new object[] { ic });
}
//ic.Dispose();
}
private async void ImgOverlay_Tapped(object sender, TappedRoutedEventArgs e)
{
var fop = new Windows.Storage.Pickers.FileOpenPicker();
WinRT.Interop.InitializeWithWindow.Initialize(fop, hWndMain);
fop.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
var types = new List<string> { ".jpg", ".png", ".gif", ".bmp", ".tif" };
foreach (var type in types)
fop.FileTypeFilter.Add(type);
var file = await fop.PickSingleFileAsync();
if (file != null)
{
using (var stream = await file.OpenAsync(FileAccessMode.Read))
{
//m_OverlayImage?.Dispose();
var decoder = await BitmapDecoder.CreateAsync(stream);
m_OverlayImage = await decoder.GetSoftwareBitmapAsync();
if (m_OverlayImage.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || m_OverlayImage.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
m_OverlayImage = SoftwareBitmap.Convert(m_OverlayImage, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(m_OverlayImage);
imgOverlay.Source = source;
}
}
}
private SoftwareBitmap m_OverlayImage, m_OverlayImageScaled = null;
private async void LoadOverlayImage()
{
string sExePath = AppContext.BaseDirectory;
string sImagePath = System.IO.Path.Combine(sExePath, "Assets\\Butterfly_Blue_126x100.png");
StorageFile file = await StorageFile.GetFileFromPathAsync(sImagePath);
using (var stream = await file.OpenAsync(FileAccessMode.Read))
{
var decoder = await BitmapDecoder.CreateAsync(stream);
m_OverlayImage = await decoder.GetSoftwareBitmapAsync();
if (m_OverlayImage.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || m_OverlayImage.BitmapAlphaMode == BitmapAlphaMode.Straight)
{
m_OverlayImage = SoftwareBitmap.Convert(m_OverlayImage, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(m_OverlayImage);
imgOverlay.Source = source;
}
}
bool m_bCameraRender = false;
private void CompositionTarget_Rendering(object sender, object e)
{
HRESULT hr = HRESULT.S_OK;
hr = Render();
}
HRESULT Render()
{
HRESULT hr = HRESULT.S_OK;
if (m_pD2DDeviceContext != null)
{
m_pD2DDeviceContext.BeginDraw();
//m_pD2DDeviceContext.Clear(new ColorF(ColorF.Enum.Orange, 1.0f));
m_pD2DDeviceContext.Clear(new ColorF(ColorF.Enum.Black, 1.0f));
//m_pD2DDeviceContext.Clear(null);
m_pD2DDeviceContext.GetSize(out D2D1_SIZE_F size);
if (m_pD2DBitmap1 != null)
{
m_pD2DBitmap1.GetSize(out D2D1_SIZE_F sizeBmpBackground);
float renderTargetAspect = size.width / size.height;
float bitmapAspect = sizeBmpBackground.width / sizeBmpBackground.height;
D2D1_RECT_F destRectBackground;
if (bitmapAspect > renderTargetAspect)
{
// Bitmap is wider than the render target
float scaledHeight = size.width / bitmapAspect;
float verticalOffset = (size.height - scaledHeight) / 2.0f;
destRectBackground = new D2D1_RECT_F(0.0f, verticalOffset, size.width, verticalOffset + scaledHeight);
}
else
{
// Bitmap is taller than the render target
float scaledWidth = size.height * bitmapAspect;
float horizontalOffset = (size.width - scaledWidth) / 2.0f;
destRectBackground = new D2D1_RECT_F(horizontalOffset, 0.0f, horizontalOffset + scaledWidth, size.height);
}
D2D1_RECT_F sourceRectBackground = new D2D1_RECT_F(0.0f, 0.0f, sizeBmpBackground.width, sizeBmpBackground.height);
if (!m_bCameraRender)
{
m_pD2DDeviceContext.SetTransform(Matrix3x2F.Identity());
m_pD2DDeviceContext.DrawBitmap(m_pD2DBitmap1, ref destRectBackground, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, ref sourceRectBackground);
}
else
{
if (m_pD3D11DevicePtr != IntPtr.Zero && m_SharedHandle != IntPtr.Zero)
{
// If Effect and resizing
// D3D11 ERROR: ID3D11Device::OpenSharedResource: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #381: DEVICE_OPEN_SHARED_RESOURCE_INVALIDARG_RETURN]
ID3D11Device pD3D11Device = Marshal.GetObjectForIUnknown(m_pD3D11DevicePtr) as ID3D11Device;
hr = pD3D11Device.OpenSharedResource(m_SharedHandle, typeof(D3D11.ID3D11Texture2D).GUID, out IntPtr texturePtr);
if (SUCCEEDED(hr))
{
D3D11.ID3D11Texture2D pSharedTextureMainThread = Marshal.GetObjectForIUnknown(texturePtr) as D3D11.ID3D11Texture2D;
IDXGISurface pDXGISurface = pSharedTextureMainThread as IDXGISurface;
D2D1_BITMAP_PROPERTIES1 bitmapProperties = new D2D1_BITMAP_PROPERTIES1();
bitmapProperties.bitmapOptions = D2D1_BITMAP_OPTIONS.D2D1_BITMAP_OPTIONS_NONE;// D2D1_BITMAP_OPTIONS.D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS.D2D1_BITMAP_OPTIONS_CANNOT_DRAW;
//bitmapProperties.pixelFormat = D2DTools.PixelFormat(DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE.D2D1_ALPHA_MODE_IGNORE);
bitmapProperties.pixelFormat = D2DTools.PixelFormat(DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE.D2D1_ALPHA_MODE_PREMULTIPLIED);
//uint nDPI = GetDpiForWindow(hWndMain);
//bitmapProperties.dpiX = nDPI;
//bitmapProperties.dpiY = nDPI;
bitmapProperties.dpiX = 96.0f;
bitmapProperties.dpiY = 96.0f;
//ID2D1ColorContext1 pD2D1ColorContext1 = null;
//hr = m_pD2DDeviceContext5.CreateColorContextFromDxgiColorSpace(DXGI_COLOR_SPACE_TYPE.DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709, out pD2D1ColorContext1);
//if (SUCCEEDED(hr) && pD2D1ColorContext1 != null)
// bitmapProperties.colorContext = pD2D1ColorContext1;
ID2D1Bitmap1 pD2DBitmap1;
hr = m_pD2DDeviceContext.CreateBitmapFromDxgiSurface(pDXGISurface, bitmapProperties, out pD2DBitmap1);
if (SUCCEEDED(hr) && pD2DBitmap1 != null)
{
pD2DBitmap1.GetSize(out sizeBmpBackground);
renderTargetAspect = size.width / size.height;
bitmapAspect = sizeBmpBackground.width / sizeBmpBackground.height;
if (bitmapAspect > renderTargetAspect)
{
// Bitmap is wider than the render target
float scaledHeight = size.width / bitmapAspect;
float verticalOffset = (size.height - scaledHeight) / 2.0f;
destRectBackground = new D2D1_RECT_F(0.0f, verticalOffset, size.width, verticalOffset + scaledHeight);
}
else
{
// Bitmap is taller than the render target
float scaledWidth = size.height * bitmapAspect;
float horizontalOffset = (size.width - scaledWidth) / 2.0f;
destRectBackground = new D2D1_RECT_F(horizontalOffset, 0.0f, horizontalOffset + scaledWidth, size.height);
}
sourceRectBackground = new D2D1_RECT_F(0.0f, 0.0f, sizeBmpBackground.width, sizeBmpBackground.height);
//pD2DBitmap1.GetColorContext(colorContext: out ID2D1ColorContext pD2D1ColorContext);
//D2D1_COLOR_SPACE cs = pD2D1ColorContext.GetColorSpace();
// If no custom effect, Brightness is too high with VideoProcessor : Color space or gamma mismatch ?
//if (!(cbOverlayImage.IsChecked == true || tsMirror.IsOn || cbGrayscale.IsChecked == true ||
// cbRGB.IsChecked == true || cbInvert.IsChecked == true || cbBrightness.IsChecked == true ||
// cbEmboss.IsChecked == true || cbEdgeDetection.IsChecked == true || cbGaussianBlur.IsChecked == true ||
// cbSharpen.IsChecked == true || cbVignette.IsChecked == true) || (tsRotation.IsOn || cbFaceDetection.IsChecked == true))
//{
// ID2D1ColorContext1 pD2DColorContextSource = null;
// hr = m_pD2DDeviceContext5.CreateColorContextFromDxgiColorSpace(DXGI_COLOR_SPACE_TYPE.DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709, out pD2DColorContextSource);
// IntPtr pD2DColorContextSourcePtr = Marshal.GetComInterfaceForObject(pD2DColorContextSource, typeof(ID2D1ColorContext1));
// ID2D1ColorContext1 pD2DColorContextDest = null;
// //hr = m_pD2DDeviceContext.CreateColorContext(D2D1_COLOR_SPACE., IntPtr.Zero, 0, out pD2DColorContextDest);
// hr = m_pD2DDeviceContext5.CreateColorContextFromDxgiColorSpace(DXGI_COLOR_SPACE_TYPE.DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709, out pD2DColorContextDest);
// IntPtr pD2DColorContextDestPtr = Marshal.GetComInterfaceForObject(pD2DColorContextDest, typeof(ID2D1ColorContext));
// ID2D1Effect pEffect = null;
// hr = m_pD2DDeviceContext.CreateEffect(CLSID_D2D1ColorManagement, out pEffect);
// pEffect.SetInput(0, pD2DBitmap1);
// SetEffectIntPtr(pEffect, (uint)D2D1_COLORMANAGEMENT_PROP.D2D1_COLORMANAGEMENT_PROP_SOURCE_COLOR_CONTEXT, pD2DColorContextSourcePtr);
// SetEffectIntPtr(pEffect, (uint)D2D1_COLORMANAGEMENT_PROP.D2D1_COLORMANAGEMENT_PROP_DESTINATION_COLOR_CONTEXT, pD2DColorContextDestPtr);
// SetEffectInt(pEffect, (uint)D2D1_COLORMANAGEMENT_PROP.D2D1_COLORMANAGEMENT_PROP_QUALITY, (uint)D2D1_COLORMANAGEMENT_QUALITY.D2D1_COLORMANAGEMENT_QUALITY_BEST);
// float scaleX = (destRectBackground.right - destRectBackground.left) / sizeBmpBackground.width;
// float scaleY = (destRectBackground.bottom - destRectBackground.top) / sizeBmpBackground.height;
// float offsetX = destRectBackground.left;
// float offsetY = destRectBackground.top;
// var transform = Matrix3x2F.Scale(scaleX, scaleY) * Matrix3x2F.Translation(offsetX, offsetY);
// m_pD2DDeviceContext.SetTransform(transform);
// ID2D1Image pOutputImage = null;
// pEffect.GetOutput(out pOutputImage);
// D2D1_POINT_2F pt = new D2D1_POINT_2F(0, 0);
// D2D1_RECT_F sourceRectangle = new D2D1_RECT_F(0, 0, size.width, size.height);
// m_pD2DDeviceContext.DrawImage(pOutputImage, ref pt, ref sourceRectBackground, D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR, D2D1_COMPOSITE_MODE.D2D1_COMPOSITE_MODE_SOURCE_OVER);
// SafeRelease(ref pD2DColorContextSource);
// Marshal.Release(pD2DColorContextSourcePtr);
// SafeRelease(ref pD2DColorContextDest);
// Marshal.Release(pD2DColorContextDestPtr);
// SafeRelease(ref pEffect);
// SafeRelease(ref pOutputImage);
//}
//else
//{
// m_pD2DDeviceContext.DrawBitmap(pD2DBitmap1, ref destRectBackground, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, ref sourceRectBackground);
//}
m_pD2DDeviceContext.DrawBitmap(pD2DBitmap1, ref destRectBackground, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, ref sourceRectBackground);
if (m_DetectedFaces.Count > 0)
{
float nScaleX = (destRectBackground.right - destRectBackground.left) / sizeBmpBackground.width;
float nScaleY = (destRectBackground.bottom - destRectBackground.top) / sizeBmpBackground.height;
float nOffsetX = destRectBackground.left;
float nOffsetY = destRectBackground.top;
// "Collection was modified; enumeration operation may not execute"
//foreach (var faceBounds in m_DetectedFaces)
for (int i = 0; i < m_DetectedFaces.Count; i++)
{
var faceBounds = m_DetectedFaces[i];
float nFaceX = faceBounds.X * nScaleX + nOffsetX;
float nFaceY = faceBounds.Y * nScaleY + nOffsetY;
float nFaceWidth = faceBounds.Width * nScaleX;
float nFaceHeight = faceBounds.Height * nScaleY;
var rect = RectF(nFaceX, nFaceY, nFaceX + nFaceWidth, nFaceY + nFaceHeight);
m_pD2DDeviceContext.DrawRectangle(rect, m_pD2DSolidColorBrushPink, 2.0f);
}
}
SafeRelease(ref pD2DBitmap1);
SafeRelease(ref bitmapProperties.colorContext);
}
SafeRelease(ref pSharedTextureMainThread);
Marshal.Release(texturePtr);
//SafeRelease(ref pD2D1ColorContext1);
SafeRelease(ref pDXGISurface);
}
else
{
//Debug.WriteLine($"m_SharedHandle: {m_SharedHandle}");
}
SafeRelease(ref pD3D11Device);
}
}
}
// For test
// m_pD2DDeviceContext.FillEllipse(Ellipse(new Direct2D.D2D1_POINT_2F(300, 300), 100.0f, 100.0f), m_pD2DMainBrush);
hr = m_pD2DDeviceContext.EndDraw(out ulong tag1, out ulong tag2);
if ((uint)hr == D2DTools.D2DERR_RECREATE_TARGET)
{
m_pD2DDeviceContext.SetTarget(null);
SafeRelease(ref m_pD2DDeviceContext);
hr = CreateDeviceContext();
CleanDeviceResources();
hr = CreateDeviceResources();
hr = CreateSwapChain(IntPtr.Zero);
hr = ConfigureSwapChain(hWndMain);
}
hr = m_pDXGISwapChain1.Present(1, 0);
}
return (hr);
}
private async void FillDevices()
{
cmbDevices.Items.Clear();
m_deviceList = await DeviceInformation.FindAllAsync(MediaDevice.GetVideoCaptureSelector());
foreach (var device in m_deviceList)
{
devices.Add(new ComboBoxItem() { Content = device.Name });
}
}
private void cbGrayscale_Checked(object sender, RoutedEventArgs e)
{
if (cbRGB.IsChecked == true)
{
cbRGB.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
}
private void cbRGB_Checked(object sender, RoutedEventArgs e)
{
if (cbGrayscale.IsChecked == true)
{
cbGrayscale.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
}
private void cbEmboss_Checked(object sender, RoutedEventArgs e)
{
if (cbRGB.IsChecked == true)
{
cbRGB.IsChecked = false;
}
if (cbGrayscale.IsChecked == true)
{
cbGrayscale.IsChecked = false;
}
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
if (cbGaussianBlur.IsChecked == true)
{
cbGaussianBlur.IsChecked = false;
}
if (cbSharpen.IsChecked == true)
{
cbSharpen.IsChecked = false;
}
if (cbVignette.IsChecked == true)
{
cbVignette.IsChecked = false;
}
if (cbFaceDetection.IsChecked == true)
{
cbFaceDetection.IsChecked = false;
}
}
private void cbGaussianBlur_Checked(object sender, RoutedEventArgs e)
{
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbSharpen.IsChecked == true)
{
cbSharpen.IsChecked = false;
}
if (cbVignette.IsChecked == true)
{
cbVignette.IsChecked = false;
}
if (cbFaceDetection.IsChecked == true)
{
cbFaceDetection.IsChecked = false;
}
}
private void cbSharpen_Checked(object sender, RoutedEventArgs e)
{
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbGaussianBlur.IsChecked == true)
{
cbGaussianBlur.IsChecked = false;
}
if (cbVignette.IsChecked == true)
{
cbVignette.IsChecked = false;
}
//if (cbFaceDetection.IsChecked == true)
//{
// cbFaceDetection.IsChecked = false;
//}
}
private void cbEdgeDetection_Checked(object sender, RoutedEventArgs e)
{
if (cbRGB.IsChecked == true)
{
cbRGB.IsChecked = false;
}
if (cbGrayscale.IsChecked == true)
{
cbGrayscale.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbGaussianBlur.IsChecked == true)
{
cbGaussianBlur.IsChecked = false;
}
if (cbSharpen.IsChecked == true)
{
cbSharpen.IsChecked = false;
}
if (cbVignette.IsChecked == true)
{
cbVignette.IsChecked = false;
}
if (cbFaceDetection.IsChecked == true)
{
cbFaceDetection.IsChecked = false;
}
}
private void cbVignette_Checked(object sender, RoutedEventArgs e)
{
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbGaussianBlur.IsChecked == true)
{
cbGaussianBlur.IsChecked = false;
}
if (cbSharpen.IsChecked == true)
{
cbSharpen.IsChecked = false;
}
}
private void cbFaceDetection_Checked(object sender, RoutedEventArgs e)
{
if (cbEmboss.IsChecked == true)
{
cbEmboss.IsChecked = false;
}
if (cbEdgeDetection.IsChecked == true)
{
cbEdgeDetection.IsChecked = false;
}
if (cbGaussianBlur.IsChecked == true)
{
cbGaussianBlur.IsChecked = false;
}
}
int m_Red = 0, m_Green = 0, m_Blue = 0;
float m_StrengthEmboss = 5.0f;
float m_StrengthEdgeDetection = 0.5f;
float m_DeviationGaussianBlur = 3.0f;
float m_SharpnessSharpen = 0.5f;
private void sliderR_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_Red = (int)s.Value;
}
private void sliderG_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_Green = (int)s.Value;
}
private void sliderB_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_Blue = (int)s.Value;
}
private void sliderStrengthEmboss_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_StrengthEmboss = (float)s.Value;
}
private void sliderStandardDeviationGaussianBlur_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_DeviationGaussianBlur = (float)s.Value;
}
private void sliderSharpnessSharpen_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_SharpnessSharpen = (float)s.Value;
}
private void sliderStrengthEdgeDetection_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider s = sender as Slider;
m_StrengthEdgeDetection = (float)s.Value;
}
private async void rectVignetteColor_Tapped(object sender, TappedRoutedEventArgs e)
{
var picker = new ColorPicker
{
IsAlphaEnabled = true,
Color = ((SolidColorBrush)rectVignetteColor.Fill).Color
};
var dialog = new ContentDialog
{
Title = "Choose a Color",
Content = picker,
PrimaryButtonText = "OK",
CloseButtonText = "Cancel",
XamlRoot = this.Content.XamlRoot
};
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
rectVignetteColor.Fill = new SolidColorBrush(picker.Color);
}
}
private void cmbFrameFormats_SelectionChanged(object sender, Microsoft.UI.Xaml.Controls.SelectionChangedEventArgs e)
{
var comboBox = sender as Microsoft.UI.Xaml.Controls.ComboBox;
if (comboBox.SelectedItem is MediaFrameFormatWrapper selectedFormat)
{
string formatDetails = selectedFormat.DisplayString;
//int nWidth = selectedFormat.Width;
//int nHeight = selectedFormat.Height;
//int nNumerator = selectedFormat.FrameRateNumerator;
//int nDenominator = selectedFormat.FrameRateDenominator;
m_currentFrameFormat = selectedFormat.Format;
//System.Diagnostics.Debug.WriteLine($"Selected Format: {formatDetails}");
}
}
public class MediaFrameFormatWrapper
{
public MediaFrameFormat Format { get; }
public MediaFrameFormatWrapper(MediaFrameFormat format)
{
Format = format;
}
//public uint VideoFormatWidth { get; set; }
//public uint VideoFormatHeight { get; set; }
//public string DisplayString => $"{Format.Subtype}-{Format.VideoFormat.Width}*{Format.VideoFormat.Height}";
public string DisplayString => string.Format("{0} | {1} | {2} x {3} | {4:#.##}fps",
Format.MajorType,
Format.Subtype,
Format.VideoFormat?.Width,
Format.VideoFormat?.Height,
Math.Round((double)Format.FrameRate.Numerator / Format.FrameRate.Denominator, 2));
}
private async Task<bool> InitializeMediaCapture()
{
if (m_MediaCapture != null)
{
m_MediaCapture.Dispose();
m_MediaCapture = null;
}
m_MediaCapture = new();
//var audioDeviceId = await GetAudioCaptureDevicesAsync();
//var mfsg = (await MediaFrameSourceGroup.FindAllAsync())?.FirstOrDefault();
var captureSettings = new MediaCaptureInitializationSettings
{
//AudioDeviceId = audioDeviceId, // Select the desired microphone
//AudioDeviceId = string.Empty,
VideoDeviceId = m_deviceList[cmbDevices.SelectedIndex].Id,// \\?\ROOT#IMAGE#0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
//SourceGroup = mfsg,
StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
SharingMode = MediaCaptureSharingMode.ExclusiveControl,
MediaCategory = MediaCategory.Media,
AudioProcessing = AudioProcessing.Default,
//AudioProcessing = AudioProcessing.Raw,
// frame?.VideoMediaFrame =>
MemoryPreference = MediaCaptureMemoryPreference.Auto // GPU => SoftwareBitmap = null, Direct3DSurface != null
//MemoryPreference = MediaCaptureMemoryPreference.Cpu // SoftwareBitmap != null, Direct3DSurface = null
};
//IReadOnlyList<MediaCaptureVideoProfile> profiles = MediaCapture.FindKnownVideoProfiles(captureSettings.VideoDeviceId, KnownVideoProfile.VideoRecording);
await m_MediaCapture.InitializeAsync(captureSettings);
//var videoDeviceController = m_MediaCapture.VideoDeviceController;
//var supportedVideoFrameRates = videoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
//var regionsControl = m_MediaCapture.VideoDeviceController.RegionsOfInterestControl;
//bool bFaceDetectionFocusAndExposureSupported = regionsControl.MaxRegions > 0 &&
// (regionsControl.AutoExposureSupported || regionsControl.AutoFocusSupported);
//if (bFaceDetectionFocusAndExposureSupported)
// cbFaceDetection.Visibility = Visibility.Visible;
//else
// cbFaceDetection.Visibility = Visibility.Collapsed;
//cbFaceDetection.Visibility = Visibility.Visible;
return true;
}
private async void cmbDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
cmbFrameFormats.IsEnabled = false;
bool bStatus = await InitializeMediaCapture();
if (bStatus)
{
MediaFormats.Clear();
m_currentFrameFormat = null;
//var frameSource = m_MediaCapture.FrameSources.Values.FirstOrDefault(source => source.Info.SourceKind == MediaFrameSourceKind.Color);
//MediaFrameSource frameSource = null;
MediaFrameSource previewSource = m_MediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoPreview
&& source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
if (previewSource != null)
{
m_frameSource = previewSource;
}
else
{
MediaFrameSource recordSource = m_MediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoRecord
&& source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
if (recordSource != null)
{
m_frameSource = recordSource;
}
}
if (m_frameSource != null)
{
var formatList = m_frameSource.SupportedFormats;
foreach (var format in formatList)
{
// Too slow on my PC for big formats
if (format.VideoFormat.Width <= 3000)
{
MediaFormats.Add(new MediaFrameFormatWrapper(format));
}
}
cmbFrameFormats.IsEnabled = true;
}
}
else
{
m_MediaCapture = null;
}
}
private async ValueTask<SoftwareBitmap> ScaleSoftwareBitmapAsync(SoftwareBitmap inputBitmap, uint nNewWidth, uint nNewHeight)
{
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, memoryStream);
encoder.SetSoftwareBitmap(inputBitmap);
encoder.BitmapTransform.ScaledWidth = nNewWidth;
encoder.BitmapTransform.ScaledHeight = nNewHeight;
encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant; // High quality
await encoder.FlushAsync();
var decoder = await BitmapDecoder.CreateAsync(memoryStream);
return await decoder.GetSoftwareBitmapAsync(inputBitmap.BitmapPixelFormat, inputBitmap.BitmapAlphaMode);
}
}
IMediaExtension m_MirrorEffect = null, m_MirrorEffectRecord = null;
IMediaExtension m_GrayScaleD2DEffect = null, m_GrayScaleD2DEffectRecord = null;
IMediaExtension m_RGBD2DEffect = null, m_RGBD2DEffectRecord = null;
IMediaExtension m_RotationEffect = null, m_RotationEffectRecord = null;
IMediaExtension m_InvertD2DEffect = null, m_InvertD2DEffectRecord = null;
IMediaExtension m_BrightnessEffect = null, m_BrightnessEffectRecord = null;
IMediaExtension m_OverlayImageEffect = null, m_OverlayImageEffectRecord = null;
IMediaExtension m_EmbossD2DEffect = null, m_EmbossD2DEffectRecord = null;
IMediaExtension m_EdgeDetectionD2DEffect = null, m_EdgeDetectionD2DEffectRecord = null;
IMediaExtension m_GaussianBlurD2DEffect = null, m_GaussianBlurD2DEffectRecord = null;
IMediaExtension m_SharpenD2DEffect = null, m_SharpenD2DEffectRecord = null;
IMediaExtension m_VignetteD2DEffect = null, m_VignetteD2DEffectRecord = null;
FaceDetectionEffect m_FaceDetectionEffect = null;
IMediaExtension m_NullEffect = null;
private void SetEffectFloat(ID2D1Effect pEffect, uint nEffect, float fValue)
{
float[] aFloatArray = { fValue };
int nDataSize = aFloatArray.Length * Marshal.SizeOf(typeof(float));
IntPtr pData = Marshal.AllocHGlobal(nDataSize);
Marshal.Copy(aFloatArray, 0, pData, aFloatArray.Length);
HRESULT hr = pEffect.SetValue(nEffect, D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, pData, (uint)nDataSize);
Marshal.FreeHGlobal(pData);
}
private void SetEffectInt(ID2D1Effect pEffect, uint nEffect, uint nValue)
{
IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32)));
Marshal.WriteInt32(pData, (int)nValue);
HRESULT hr = pEffect.SetValue(nEffect, D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, pData, (uint)Marshal.SizeOf(typeof(Int32)));
Marshal.FreeHGlobal(pData);
}
private void SetEffectIntPtr(ID2D1Effect pEffect, uint nEffect, IntPtr pPointer)
{
IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
Marshal.WriteIntPtr(pData, pPointer);
HRESULT hr = pEffect.SetValue(nEffect, D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN, pData, (uint)Marshal.SizeOf(typeof(IntPtr)));
Marshal.FreeHGlobal(pData);
}
private async void btn_PreviewVideo_Click(object sender, RoutedEventArgs e)
{
if (!m_bPreviewing)
{
if (m_frameSource != null)
{
if (m_currentFrameFormat != null)
{
await m_frameSource.SetFormatAsync(m_currentFrameFormat);
m_bCameraRender = true;
if (!((m_MediaCapture.MediaCaptureSettings.VideoDeviceCharacteristic == VideoDeviceCharacteristic.AllStreamsIdentical ||
m_MediaCapture.MediaCaptureSettings.VideoDeviceCharacteristic == VideoDeviceCharacteristic.PreviewRecordStreamsIdentical)
&& m_bRecording))
{
// Test other VideoTransformEffectDefinition
//var cropDefinition = new VideoTransformEffectDefinition();
//cropDefinition.CropRectangle = new Rect(200, 200, 400, 400);
//var c = await m_MediaCapture.AddVideoEffectAsync(cropDefinition, MediaStreamType.VideoPreview);
if (cbOverlayImage.IsChecked == true)
{
var overlayImageEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.OverlayImageEffect");
m_OverlayImageEffect = await m_MediaCapture.AddVideoEffectAsync(overlayImageEffectDefinition, MediaStreamType.VideoPreview);
//string sExePath = AppContext.BaseDirectory;
//string sImagePath = System.IO.Path.Combine(sExePath, "Assets\\Butterfly_Blue_126x100.png");
//m_OverlayImageEffect.SetProperties(new PropertySet() { { "ImagePath", sImagePath } });
if (m_OverlayImageScaled != null)
{
m_OverlayImageScaled.Dispose();
m_OverlayImageScaled = null;
}
if (m_OverlayImage.PixelWidth > m_currentFrameFormat.VideoFormat.Width / 2)
{
double nRatio = (double)m_OverlayImage.PixelWidth / (double)(m_currentFrameFormat.VideoFormat.Width / 2);
m_OverlayImageScaled = await ScaleSoftwareBitmapAsync(m_OverlayImage, m_currentFrameFormat.VideoFormat.Width / 2, (uint)(m_OverlayImage.PixelHeight / nRatio));
}
else
{
m_OverlayImageScaled = SoftwareBitmap.Copy(m_OverlayImage);
}
m_OverlayImageEffect.SetProperties(new PropertySet() { { "OverlayImage", m_OverlayImageScaled } });
}
if (tsMirror.IsOn)
{
var mirrorEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.MirrorEffect");
m_MirrorEffect = await m_MediaCapture.AddVideoEffectAsync(mirrorEffectDefinition, MediaStreamType.VideoPreview);
m_MirrorEffect.SetProperties(new PropertySet() { { "IsVertical", (m_Mirror == MediaMirroringOptions.Horizontal) ? false : true } });
}
if (cbEmboss.IsChecked == true)
{
var embossD2DEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.EmbossD2DEffect");
m_EmbossD2DEffect = await m_MediaCapture.AddVideoEffectAsync(embossD2DEffectDefinition, MediaStreamType.VideoPreview);
m_EmbossD2DEffect.SetProperties(new PropertySet() { { "StrengthEmboss", m_StrengthEmboss } });
}
if (cbGaussianBlur.IsChecked == true)
{
var gaussianBlurD2DEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.GaussianBlurD2DEffect");
m_GaussianBlurD2DEffect = await m_MediaCapture.AddVideoEffectAsync(gaussianBlurD2DEffectDefinition, MediaStreamType.VideoPreview);
m_GaussianBlurD2DEffect.SetProperties(new PropertySet() { { "DeviationGaussianBlur", m_DeviationGaussianBlur } });
}
if (cbEdgeDetection.IsChecked == true)
{
var edgeDetectionD2DEffectDefinition = new VideoEffectDefinition("VideoEffectComponent.EdgeDetectionD2DEffect");
m_EdgeDetectionD2DEffect = await m_MediaCapture.AddVideoEffectAsync(edgeDetectionD2DEffectDefinition, MediaStreamType.VideoPreview);
m_EdgeDetectionD2DEffect.SetProperties(new PropertySet() { { "StrengthEdgeDetection", m_StrengthEdgeDetection } });
}
if (tsRotation.IsOn)
{
// 0xc00d36b4 MF_E_INVALIDMEDIATYPE
// "Scaler unavaliable for type"
var rotationEffectDefinition = new VideoTransformEffectDefinition();
rotationEffectDefinition.Rotation = m_Rotation;
m_RotationEffect = await m_MediaCapture.AddVideoEffectAsync(rotationEffectDefinition, MediaStreamType.VideoPreview);
}
// https://learn.microsoft.com/en-us/windows/apps/develop/camera/scene-analysis-for-media-capture#face-detection-effect
if (cbFaceDetection.IsChecked == true)
{
var faceDetectionEffectDefinition = new FaceDetectionEffectDefinition();
faceDetectionEffectDefinition.SynchronousDetectionEnabled = false;
faceDetectionEffectDefinition.DetectionMode = FaceDetectionMode.HighQuality;// FaceDetectionMode.HighPerformance;
m_FaceDetectionEffect = (FaceDetectionEffect)await m_MediaCapture.AddVideoEffectAsync(faceDetectionEffectDefinition, MediaStreamType.VideoPreview);
m_FaceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(33);
m_FaceDetectionEffect.Enabled = true;
m_FaceDetectionEffect.FaceDetected += FaceDetectionEffect_FaceDetected;
}
if (cbSharpen.IsChecked == true)
{