Пример #1
0
 //<SnippetSetPreviewRotationAsync>
 private async Task SetPreviewRotationAsync()
 {
     if (!_externalCamera)
     {
         // Add rotation metadata to the preview stream to make sure the aspect ratio / dimensions match when rendering and getting preview frames
         var  rotation    = _rotationHelper.GetCameraPreviewOrientation();
         var  props       = mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);
         Guid RotationKey = new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1");
         props.Properties.Add(RotationKey, CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(rotation));
         await mediaCapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, props, null);
     }
 }
Пример #2
0
        //</SnippetSetPreviewRotationAsync>

        //<SnippetHelperOrientationChanged>
        private async void RotationHelper_OrientationChanged(object sender, bool updatePreview)
        {
            if (updatePreview)
            {
                await SetPreviewRotationAsync();
            }
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                // Rotate the buttons in the UI to match the rotation of the device
                var angle     = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetUIOrientation());
                var transform = new RotateTransform {
                    Angle = angle
                };

                // The RenderTransform is safe to use (i.e. it won't cause layout issues) in this case, because these buttons have a 1:1 aspect ratio
                CapturePhotoButton.RenderTransform = transform;
                CapturePhotoButton.RenderTransform = transform;
            });
        }
Пример #3
0
        //</SnippetCapturePhotoWithOrientation>

        //<SnippetStartRecordingWithOrientationAsync>
        private async Task StartRecordingWithOrientationAsync()
        {
            try
            {
                var videoFile = await KnownFolders.VideosLibrary.CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption.GenerateUniqueName);

                var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

                var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(
                    _rotationHelper.GetCameraCaptureOrientation());
                Guid RotationKey = new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1");
                encodingProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));

                await mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoFile);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception when starting video recording: {0}", ex.ToString());
            }
        }