Rotation and mirroring

Rotation

In most cases, you will want your app to rotate the preview window when the user rotates their device. To do this, you can call the MediaCapture object’s SetPreviewRotation and SetRecordRotation methods when the orientation of the device changes.
For example:
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);

If you want to record in portrait mode, you will also need to swap the width and height in all video profiles supplied to CaptureSession and call MediaCapture.SetEncodingPropertiesAsync to supply it with this new profile to use for preview.
For example:
await mediaCapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, captureSession.CaptureEncodingProfile.Video, new MediaPropertySet());

Mirroring

You may also want to detect whether you are using your front camera and mirror the preview image if so. This will ensure that your user sees the same thing they would expect to see in a mirror (as opposed to what the camera sees).

To detect whether a camera is a front camera:

var videoDevices = await DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
var frontCameras = videoDevices.Where(d => d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
Note: The recommended way to set the preview window to mirror is by setting the CaptureElement.FlowDirection property:
captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft;

Combining mirroring and rotation

Be aware that when mirroring, and in portrait mode, you will need to reverse the rotation settings supplied to MediaCapture.SetPreviewRotation and MediaCapture.SetRecordRotation. For example: use 90 degrees instead of 270 degrees and vice versa.

Last edited Aug 20, 2014 at 9:59 PM by timgreenfield, version 2