コード例 #1
0
        /// <summary>
        /// Reads the current orientation of the app and calculates the VideoRotation necessary to ensure the preview is rendered in the correct orientation,
        /// for the situations where the requested AutoRotationPreferences couldn't be applied
        /// </summary>
        /// <param name="sourceRotation">The rotation value to use in SetPreviewRotation</param>
        /// <param name="rotationDegrees">The accompanying rotation metadata with which to tag the preview stream via SetEncodingPropertiesAsync</param>
        private void CalculatePreviewRotation(out VideoRotation sourceRotation, out int rotationDegrees)
        {
            rotationDegrees = ConvertDisplayOrientationToDegrees(_displayOrientation);

            // The rotation direction needs to be inverted if the preview is being mirrored
            if (_mirroringPreview)
            {
                rotationDegrees = 360 - rotationDegrees;
            }

            switch (_displayOrientation)
            {
            case DisplayOrientations.Portrait:
                sourceRotation = _mirroringPreview ? VideoRotation.Clockwise270Degrees : VideoRotation.Clockwise90Degrees;
                break;

            case DisplayOrientations.LandscapeFlipped:
                // No need to invert this rotation, as rotating 180 degrees is the same either way
                sourceRotation = VideoRotation.Clockwise180Degrees;
                break;

            case DisplayOrientations.PortraitFlipped:
                sourceRotation = _mirroringPreview ? VideoRotation.Clockwise90Degrees : VideoRotation.Clockwise270Degrees;
                break;

            case DisplayOrientations.Landscape:
            default:
                sourceRotation = VideoRotation.None;
                break;
            }
        }
コード例 #2
0
 public async Task StartPreviewAsync(VideoRotation videoRotation)
 {
     try
     {
         if (mediaCapture == null)
         {
             var cameraDevice = await FindCameraDeviceByPanelAsync(Panel.Back);
             mediaCapture = new MediaCapture();
             var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
             await mediaCapture.InitializeAsync(settings);
             captureElement.Source = mediaCapture;
             await mediaCapture.StartPreviewAsync();
             isPreviewing = true;
             mediaCapture.SetPreviewRotation(videoRotation);
             displayRequest.RequestActive();
         }
         //DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
     }
     catch (UnauthorizedAccessException)
     {
         // This will be thrown if the user denied access to the camera in privacy settings
         Debug.WriteLine("The app was denied access to the camera");
     }
     catch (Exception ex)
     {
         Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
     }
 }
コード例 #3
0
        private void SetRecordOrientation(VideoRotation rotation)
        {
            var videoProperties = this._videoEncodingProfile.Video;

            if (videoProperties != null)
            {
                var width  = videoProperties.Width;
                var height = videoProperties.Height;

                switch (rotation)
                {
                case VideoRotation.None:
                case VideoRotation.Clockwise180Degrees:
                    if (height > width)
                    {
                        videoProperties.Height = width;
                        videoProperties.Width  = height;
                    }
                    break;

                case VideoRotation.Clockwise90Degrees:
                case VideoRotation.Clockwise270Degrees:
                    if (width > height)
                    {
                        videoProperties.Height = width;
                        videoProperties.Width  = height;
                    }
                    break;
                }
            }

            this._mediaCapture.SetRecordRotation(rotation);
        }
コード例 #4
0
 private void DisplayInfo_OrientationChanged(DisplayInformation sender, object args)
 {
     if (mediaCapture != null)
     {
         rotation = VideoRotationLookup(sender.CurrentOrientation, false);
         mediaCapture.SetPreviewRotation(rotation);
         mediaCapture.SetRecordRotation(rotation);
     }
 }
コード例 #5
0
        private async void UpdateOrientation(SimpleOrientation orientation)
        {
            try
            {
                VideoRotation videoRotation = VideoRotation.None;
                bool          showMap       = false;

                switch (orientation)
                {
                case SimpleOrientation.NotRotated:
                    videoRotation = VideoRotation.None;
                    break;

                case SimpleOrientation.Rotated90DegreesCounterclockwise:
                    videoRotation = VideoRotation.Clockwise90Degrees;
                    break;

                case SimpleOrientation.Rotated180DegreesCounterclockwise:
                    videoRotation = VideoRotation.Clockwise180Degrees;
                    break;

                case SimpleOrientation.Rotated270DegreesCounterclockwise:
                    videoRotation = VideoRotation.Clockwise270Degrees;
                    break;

                case SimpleOrientation.Facedown:
                case SimpleOrientation.Faceup:
                    showMap = true;
                    break;

                default:
                    break;
                }

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (PreviewScreen.Source != null)
                    {
                        PreviewScreen.Source.SetPreviewRotation(videoRotation);
                    }

                    if (showMap)
                    {
                        MapView.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        MapView.Visibility = Visibility.Collapsed;
                    }
                });
            }
            catch { }
        }
コード例 #6
0
        /// <summary>
        /// Reads the current orientation of the app and calculates the VideoRotation necessary to ensure the preview is rendered in the correct orientation.
        /// </summary>
        /// <param name="sourceRotation">The rotation value to use in MediaCapture.SetPreviewRotation.</param>
        /// <param name="rotationDegrees">The accompanying rotation metadata with which to tag the preview stream.</param>
        private void CalculatePreviewRotation(out VideoRotation sourceRotation, out int rotationDegrees)
        {
            // Note that in some cases, the rotation direction needs to be inverted if the preview is being mirrored.

            switch (displayInformation.CurrentOrientation)
            {
            case DisplayOrientations.Portrait:
                if (mirroringPreview)
                {
                    rotationDegrees = 270;
                    sourceRotation  = VideoRotation.Clockwise270Degrees;
                }
                else
                {
                    rotationDegrees = 90;
                    sourceRotation  = VideoRotation.Clockwise90Degrees;
                }
                break;

            case DisplayOrientations.LandscapeFlipped:
                // No need to invert this rotation, as rotating 180 degrees is the same either way.
                rotationDegrees = 180;
                sourceRotation  = VideoRotation.Clockwise180Degrees;
                break;

            case DisplayOrientations.PortraitFlipped:
                if (mirroringPreview)
                {
                    rotationDegrees = 90;
                    sourceRotation  = VideoRotation.Clockwise90Degrees;
                }
                else
                {
                    rotationDegrees = 270;
                    sourceRotation  = VideoRotation.Clockwise270Degrees;
                }
                break;

            case DisplayOrientations.Landscape:
            default:
                rotationDegrees = 0;
                sourceRotation  = VideoRotation.None;
                break;
            }
        }
コード例 #7
0
        public CapturePreview(MediaCapture capture, VideoRotation rotation = VideoRotation.None)
        {
            capture.SetPreviewRotation(rotation);
            var props = (VideoEncodingProperties)capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);

            if (rotation == VideoRotation.None || rotation == VideoRotation.Clockwise180Degrees)
            {
                m_width  = props.Width;
                m_height = props.Height;
            }
            else
            {
                m_width  = props.Height;
                m_height = props.Width;
            }

            m_preview = new CapturePreviewNative(this, m_width, m_height);
            m_capture = capture;
        }
コード例 #8
0
        int ConvertVideoRotationToMFRotation(VideoRotation rotation)
        {
            int MFVideoRotation = 0;

            switch (rotation)
            {
            case VideoRotation.Clockwise90Degrees:
                MFVideoRotation = 90;
                break;

            case VideoRotation.Clockwise180Degrees:
                MFVideoRotation = 180;
                break;

            case VideoRotation.Clockwise270Degrees:
                MFVideoRotation = 270;
                break;
            }
            return(MFVideoRotation);
        }
コード例 #9
0
        int ConvertVideoRotationToMFRotation(VideoRotation rotation)
        {
            int MFVideoRotation = 0; // MFVideoRotationFormat::MFVideoRotationFormat_0 in Mfapi.h

            switch (rotation)
            {
            case VideoRotation.Clockwise90Degrees:
                MFVideoRotation = 90; // MFVideoRotationFormat::MFVideoRotationFormat_90;
                break;

            case VideoRotation.Clockwise180Degrees:
                MFVideoRotation = 180; // MFVideoRotationFormat::MFVideoRotationFormat_180;
                break;

            case VideoRotation.Clockwise270Degrees:
                MFVideoRotation = 270; // MFVideoRotationFormat::MFVideoRotationFormat_270;
                break;
            }

            return(MFVideoRotation);
        }
コード例 #10
0
        async void CaptureAndRotate(MediaCapture captureMgrReal)
        {
            // <SnippetCaptureRotateAll>
            // <SnippetCaptureRotateInit>
            MediaCapture captureMgr = new MediaCapture();

            // Set the MediaCapture to a variable in App.xaml.cs to handle suspension.
            (App.Current as App).MediaCapture = captureMgr;

            await captureMgr.InitializeAsync();

            // </SnippetCaptureRotateInit>

            // <SnippetCaptureRotateSetRotate>
            captureMgr.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            // </SnippetCaptureRotateSetRotate>

            // <SnippetCaptureRotateGetRotate>
            VideoRotation previewRotation = captureMgr.GetPreviewRotation();

            // </SnippetCaptureRotateGetRotate>

            // Start capture preview.
            // capturePreview is a CaptureElement defined in XAML.
            capturePreview.Source = captureMgr;

            // Set the CaptureElement to a variable in App.xaml.cs to handle suspension.
            (App.Current as App).PreviewElement = capturePreview;

            // Lock the orientation of the display while previewing.
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;

            await captureMgr.StartPreviewAsync();

            // Set a tracking variable for preview state in App.xaml.cs
            (App.Current as App).IsPreviewing = true;
            // </SnippetCaptureRotateAll>
        }
コード例 #11
0
        /// <summary>
        /// A version of MediaCapture.SetPreviewRotation() which does not add
        /// unnecessary black bars.
        /// </summary>
        public static async Task SetPreviewRotationAsync(this MediaCapture capture, VideoRotation rotation)
        {
            // Convert VideoRotation to MFVideoRotationFormat
            uint rotationValue;

            switch (rotation)
            {
            case VideoRotation.None: rotationValue = 0; break;

            case VideoRotation.Clockwise90Degrees: rotationValue = 90; break;

            case VideoRotation.Clockwise180Degrees: rotationValue = 180; break;

            case VideoRotation.Clockwise270Degrees: rotationValue = 270; break;

            default: throw new ArgumentException("rotation");
            }

            // Rotate preview
            var props = capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);

            props.Properties.Add(RotationKey, rotationValue);
            await capture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, props, null);
        }
コード例 #12
0
        int ConvertVideoRotationToMFRotation(VideoRotation rotation)
        {
            int MFVideoRotation = 0; // MFVideoRotationFormat::MFVideoRotationFormat_0 in Mfapi.h
            switch (rotation)
            {
                case VideoRotation.Clockwise90Degrees:
                    MFVideoRotation = 90; // MFVideoRotationFormat::MFVideoRotationFormat_90;
                    break;
                case VideoRotation.Clockwise180Degrees:
                    MFVideoRotation = 180; // MFVideoRotationFormat::MFVideoRotationFormat_180;
                    break;
                case VideoRotation.Clockwise270Degrees:
                    MFVideoRotation = 270; // MFVideoRotationFormat::MFVideoRotationFormat_270;
                    break;
            }

            return MFVideoRotation;
        }
コード例 #13
0
ファイル: MainPage.xaml.cs プロジェクト: MSRCCS/AppSuite
        ///<summary>
        ///fixes the video preview orientation of the camera
        ///</summary>
        private void fixOrientation(DisplayInformation displayInfo, object args)
        {
            if (captureManager != null && takePicture == false)
            {
                currentRotation = VideoRotationLookup(displayInfo.CurrentOrientation, false);
                captureManager.SetPreviewRotation(currentRotation);
                captureManager.SetRecordRotation(currentRotation);

                //takePictureButton is a xaml button that fills the entire screen
                takePictureButton.Visibility = Visibility.Visible;
            }
        }
コード例 #14
0
 public static RTCVideoRotation ToPlatformNative(this VideoRotation nativePort) => (RTCVideoRotation)nativePort;
コード例 #15
0
        private void SetRecordOrientation(VideoRotation rotation)
        {
            var videoProperties = this._videoEncodingProfile.Video;
            if (videoProperties != null)
            {
                var width = videoProperties.Width;
                var height = videoProperties.Height;

                switch (rotation)
                {
                    case VideoRotation.None:
                    case VideoRotation.Clockwise180Degrees:
                        if (height > width)
                        {
                            videoProperties.Height = width;
                            videoProperties.Width = height;
                        }
                        break;
                    case VideoRotation.Clockwise90Degrees:
                    case VideoRotation.Clockwise270Degrees:
                        if (width > height)
                        {
                            videoProperties.Height = width;
                            videoProperties.Width = height;
                        }
                        break;
                }
            }

            this._mediaCapture.SetRecordRotation(rotation);
        }
コード例 #16
0
 private PreviewOrientation ConvertToPreviewOrientation(VideoRotation rotation)
 {
     return((PreviewOrientation)Enum.Parse(typeof(PreviewOrientation), rotation.ToString()));
 }
コード例 #17
0
        /// <summary>
        /// Reads the current orientation of the app and calculates the VideoRotation necessary to ensure the preview is rendered in the correct orientation.
        /// </summary>
        /// <param name="sourceRotation">The rotation value to use in MediaCapture.SetPreviewRotation.</param>
        /// <param name="rotationDegrees">The accompanying rotation metadata with which to tag the preview stream.</param>
        private void CalculatePreviewRotation(out VideoRotation sourceRotation, out int rotationDegrees)
        {
            // Note that in some cases, the rotation direction needs to be inverted if the preview is being mirrored.

            switch (displayInformation.CurrentOrientation)
            {
                case DisplayOrientations.Portrait:
                    if (mirroringPreview)
                    {
                        rotationDegrees = 270;
                        sourceRotation = VideoRotation.Clockwise270Degrees;
                    }
                    else
                    {
                        rotationDegrees = 90;
                        sourceRotation = VideoRotation.Clockwise90Degrees;
                    }
                    break;

                case DisplayOrientations.LandscapeFlipped:
                    // No need to invert this rotation, as rotating 180 degrees is the same either way.
                    rotationDegrees = 180;
                    sourceRotation = VideoRotation.Clockwise180Degrees;
                    break;

                case DisplayOrientations.PortraitFlipped:
                    if (mirroringPreview)
                    {
                        rotationDegrees = 90;
                        sourceRotation = VideoRotation.Clockwise90Degrees;
                    }
                    else
                    {
                        rotationDegrees = 270;
                        sourceRotation = VideoRotation.Clockwise270Degrees;
                    }
                    break;

                case DisplayOrientations.Landscape:
                default:
                    rotationDegrees = 0;
                    sourceRotation = VideoRotation.None;
                    break;
            }
        }
コード例 #18
0
ファイル: MainPage.xaml.cs プロジェクト: ChrisKaps/samples
 int ConvertVideoRotationToMFRotation(VideoRotation rotation)
 {
     int MFVideoRotation = 0;
     switch (rotation)
     {
         case VideoRotation.Clockwise90Degrees:
             MFVideoRotation = 90;
             break;
         case VideoRotation.Clockwise180Degrees:
             MFVideoRotation = 180;
             break;
         case VideoRotation.Clockwise270Degrees:
             MFVideoRotation = 270;
             break;
     }
     return MFVideoRotation;
 }