VideoEffect
VideoEffect copied to clipboard
SetPreviewRotation display issue
Hi, I wanted to make display portrait so I called
capture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
after capture initialization and I ended up having some strange black part where the rest of camera preview should have been.
Is there something I should do or some different way to achieve my goal?
You should be able to reuse the code there (there is a NuGet, but it might even be simpler to just copy/paste the code): https://github.com/mmaitre314/MediaCaptureExtensions#rotate-preview-without-extra-black-bars
@Ok, I have downloaded NuGet package and change initialization code to:
var settings = new MediaCaptureInitializationSettings();
await settings.SelectVideoDeviceAsync(VideoDeviceSelection.BackOrFirst);
var capture = new MediaCapture();
await capture.InitializeAsync(settings);
await capture.SetPreviewRotationAsync(VideoRotation.Clockwise90Degrees);
I get error message:
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll
Additional information: Access is denied.
Before I had only webcam selected in capabilities and it worked - do I need to do something more in manifest?
On MediaCaptureInitializationSettings you can try setting StreamingCaptureMode to Video. https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.streamingcapturemode.aspx
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
settings.VideoDeviceId = await GetBackOrDefaulCameraIdAsync();
var capture = new MediaCapture();
await capture.InitializeAsync(settings);
This works - but the camera preview is rotated. Adding line
capture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
after initilization works but there are black bars. But adding
await capture.SetPreviewRotationAsync(VideoRotation.Clockwise90Degrees);
Results in error:
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
WinRT information: PreviewState
Additional information: The stream number provided was invalid.
PreviewState
OK - I managed to get rid of side black bars by changing xaml to:
<CaptureElement Name="Preview" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin=".5,.5" >
<CaptureElement.RenderTransform>
<RotateTransform Angle="90" CenterX="0.5" CenterY="0.5" />
</CaptureElement.RenderTransform>
</CaptureElement>