VideoEffect icon indicating copy to clipboard operation
VideoEffect copied to clipboard

SetPreviewRotation display issue

Open wisien92 opened this issue 8 years ago • 5 comments

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? wp_ss_20160427_0002

wisien92 avatar Apr 27 '16 12:04 wisien92

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

mmaitre314 avatar Apr 27 '16 15:04 mmaitre314

@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?

wisien92 avatar Apr 28 '16 07:04 wisien92

On MediaCaptureInitializationSettings you can try setting StreamingCaptureMode to Video. https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.capture.streamingcapturemode.aspx

mmaitre314 avatar Apr 28 '16 15:04 mmaitre314

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

wisien92 avatar Apr 29 '16 08:04 wisien92

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>

wisien92 avatar Apr 29 '16 11:04 wisien92