SetPreviewRotation() public method

public SetPreviewRotation ( [ value ) : void
value [
return void
 private void DisplayInfo_OrientationChanged(DisplayInformation sender, object args)
 {
     if (_captureManager != null)
     {
         _captureManager.SetPreviewRotation(VideoRotationLookup(sender.CurrentOrientation, !isBackCameraActive));
     }
 }
        private async void This_Loaded( object sender, RoutedEventArgs e )
        {
            try
            {
                _camera = new MediaCapture();
                await _camera.InitializeAsync( new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = ( await GetBackCameraAsync() ).Id,
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                } );
                _camera.VideoDeviceController.FlashControl.Enabled = false;
                _camera.SetPreviewRotation( VideoRotation.Clockwise90Degrees );
                _camera.SetRecordRotation( VideoRotation.Clockwise90Degrees );

                CameraPreview.Source = _camera;
                await _camera.StartPreviewAsync();

                StartScanning();
            }
            catch
            {
                ErrorMessage.Visibility = Visibility.Visible;
            }
        }
Example #3
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);
     }
 }
Example #4
0
        async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
        {
            GerenteCaptura = new Windows.Media.Capture.MediaCapture();
            await GerenteCaptura.InitializeAsync();

            GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            CapturaPrevia.Source = GerenteCaptura;
            await GerenteCaptura.StartPreviewAsync();
        }
        private void DisplayProperties_OrientationChanged(object sender)
        {
            if (m_mediaCaptureMgr == null)
            {
                return;
            }

            bool previewMirroring         = m_mediaCaptureMgr.GetPreviewMirroring();
            bool counterclockwiseRotation = (previewMirroring && !m_bReversePreviewRotation) ||
                                            (!previewMirroring && m_bReversePreviewRotation);

            if (m_bRotateVideoOnOrientationChange)
            {
                m_mediaCaptureMgr.SetPreviewRotation(VideoRotationLookup(Windows.Graphics.Display.DisplayProperties.CurrentOrientation, counterclockwiseRotation));
            }
            else
            {
                m_mediaCaptureMgr.SetPreviewRotation(Windows.Media.Capture.VideoRotation.None);
            }
        }
 private void btnRotate_Click_1(object sender, RoutedEventArgs e)
 {
     if (captureMgr != null)
     {
         if (captureMgr.GetPreviewRotation() == VideoRotation.None)
         {
             captureMgr.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
         }
         else if (captureMgr.GetPreviewRotation() == VideoRotation.Clockwise90Degrees)
         {
             captureMgr.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
         }
         else if (captureMgr.GetPreviewRotation() == VideoRotation.Clockwise180Degrees)
         {
             captureMgr.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
         }
         else if (captureMgr.GetPreviewRotation() == VideoRotation.Clockwise270Degrees)
         {
             captureMgr.SetPreviewRotation(VideoRotation.None);
         }
     }
 }
Example #7
0
        private async void initCamera()
        {
            if (camera == null)
            {
                camera = new MediaCapture();
                await camera.InitializeAsync();

                camera.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
                camera.SetRecordRotation(VideoRotation.Clockwise270Degrees);
            }

            CameraPreview.Source = camera;
            await camera.StartPreviewAsync();
        }
        public async Task InitializeAsync()
        {
            // Discover all the cameras
            await EnumerateCamerasAsync();

            // Create a camera preview image source (from Imaging SDK)
            captureManager = new MediaCapture();
            MediaCaptureInitializationSettings captureSettings = new MediaCaptureInitializationSettings();
            captureSettings.VideoDeviceId = backCamera.Id;

            await captureManager.InitializeAsync(captureSettings);

            CameraPreview.Source = captureManager;
            captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            await captureManager.StartPreviewAsync();
        }
Example #9
0
        async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
        {
            GerenteCaptura = new Windows.Media.Capture.MediaCapture();
            var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Front);

            await GerenteCaptura.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id,
            });

            GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
            CapturaPrevia.Source = GerenteCaptura;
            await GerenteCaptura.StartPreviewAsync();
        }
Example #10
0
        public async Task<MediaCapture> Initialize(CaptureUse primaryUse = CaptureUse.Photo)
        {
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            mediaCapture = new MediaCapture();
            if (devices.Count() > 0)
            {
                await this.mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = devices.ElementAt(1).Id, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview });
            }  
            mediaCapture.VideoDeviceController.PrimaryUse = primaryUse;
            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

            imgEncodingProperties = ImageEncodingProperties.CreateJpeg();
            imgEncodingProperties.Width = 640;
            imgEncodingProperties.Height = 480;

            videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); 

            return mediaCapture;
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: Prepare page for display here.

            // TODO: If your application contains multiple pages, ensure that you are
            // handling the hardware Back button by registering for the
            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
            // If you are using the NavigationHelper provided by some templates,
            // this event is handled for you.

            // Create MediaCapture and init
            mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();
            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            

            // Assign to Xaml CaptureElement.Source and start preview
            capturePreview.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
        }
        public async Task InitializePreview(CaptureElement captureElement)
        {
            captureManager = new MediaCapture();

            var cameraID = await GetCameraID(Panel.Back);

            if (cameraID == null)
            {
                return;
            }

            await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id
            });

            await
                captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo,
                    maxResolution());

            captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

            StartPreview(captureElement);
        }
        public async Task InitialAsync(CaptureElement captureElement, MediaEncodingProfile profile = null, bool BackCamera = false)
        {
            if (initialized)
                Dispose(true);
            initialized = true;

            this.captureElement = captureElement;
            this.activeProfile = profile;
            if (CameraDeviceList == null)
                await EnumerateCameras();

            mediaCapture = null;
            mediaCapture = new MediaCapture();

            IsBackCamera = BackCamera;
            captureInitSettings = InitCaptureSettings(IsBackCamera);
            await mediaCapture.InitializeAsync(captureInitSettings);
            mediaCapture.VideoDeviceController.DesiredOptimization = MediaCaptureOptimization.LatencyThenQuality;
            mediaCapture.CameraStreamStateChanged += MediaCapture_CameraStreamStateChanged;
            mediaCapture.Failed += MediaCapture_Failed;
            mediaCapture.FocusChanged += MediaCapture_FocusChanged;
            mediaCapture.PhotoConfirmationCaptured += MediaCapture_PhotoConfirmationCaptured;
            mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
            mediaCapture.ThermalStatusChanged += MediaCapture_ThermalStatusChanged;
            await SetResolutionAsync();

            if (Manager.DeviceService.CurrentDevice() == DeviceTypes.Mobile)
            {
                if (IsBackCamera)
                {
                    mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                }
                else
                {
                    mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
                }
            }
            activeProfile = CreateProfile();
            mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video;

            captureElement.Source = mediaCapture;
        }
        public async void StartPreview()
        {
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var deviceInfo = devices[0]; //grab first result
            DeviceInformation rearCamera = null;

            foreach (var device in devices)
            {
                if (device.Name.ToLowerInvariant().Contains("front"))
                {
                    DeviceInformation frontCamera;
                    deviceInfo = frontCamera = device;
                    var hasFrontCamera = true;
                }
                if (device.Name.ToLowerInvariant().Contains("back"))
                {
                    rearCamera = device;
                }
            }

            var mediaSettings = new MediaCaptureInitializationSettings
            {
                MediaCategory        = MediaCategory.Communications,
                StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
                VideoDeviceId        = rearCamera.Id
            };

            var mediaCaptureManager = new Windows.Media.Capture.MediaCapture();
            await mediaCaptureManager.InitializeAsync(mediaSettings);

            var previewSink = new Windows.Phone.Media.Capture.MediaCapturePreviewSink();

            // List of supported video preview formats to be used by the default preview format selector.
            var supportedVideoFormats = new List <string> {
                "nv12", "rgb32"
            };

            // Find the supported preview format
            var availableMediaStreamProperties =
                mediaCaptureManager.VideoDeviceController.GetAvailableMediaStreamProperties(
                    Windows.Media.Capture.MediaStreamType.VideoPreview)
                .OfType <Windows.Media.MediaProperties.VideoEncodingProperties>()
                .Where(p => p != null &&
                       !String.IsNullOrEmpty(p.Subtype) &&
                       supportedVideoFormats.Contains(p.Subtype.ToLower()))
                .ToList();
            var previewFormat = availableMediaStreamProperties.FirstOrDefault();

            foreach (var property in availableMediaStreamProperties)
            {
                if (previewFormat.Width < property.Width)
                {
                    previewFormat = property;
                }
            }
            //previewFormat.Width = 480;
            //previewFormat.Height = 480;
            // Start Preview stream
            await mediaCaptureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.VideoPreview, previewFormat);

            await mediaCaptureManager.StartPreviewToCustomSinkAsync(new Windows.Media.MediaProperties.MediaEncodingProfile {
                Video = previewFormat
            }, previewSink);

            var viewfinderBrush = new VideoBrush {
                Stretch = Stretch.Uniform
            };

            // Set the source of the VideoBrush used for your preview
            Microsoft.Devices.CameraVideoBrushExtensions.SetSource(viewfinderBrush, previewSink);
            CameraPreview.Background = viewfinderBrush;


            mediaCaptureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
        }
        private async Task InitiateCameraCaptureObject(Panel deviceLocation)
        {
            try
            {
                if (_bInitializingCamera || _cameraCapture != null) return;
                _bInitializingCamera = true;
                await InitCaptureSettings(deviceLocation);
                _cameraCapture = new MediaCapture();
                await _cameraCapture.InitializeAsync(_captureInitSettings);
                //Enable QR Detector
                if (_qrDetectionModeEnabled)
                {
                    var formats = _cameraCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
                    var format = (VideoEncodingProperties)formats.OrderBy((item) =>
                    {
                        var props = (VideoEncodingProperties)item;
                        return Math.Abs(props.Height - ActualWidth) + Math.Abs(props.Width - ActualHeight);
                    }).First();
                    await _cameraCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, format);
                    var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, format.Width >= format.Height ? format.Width : format.Height, AnalyzeImage);
                    await _cameraCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties);
                    _barcodeReader = _barcodeReader ?? new BarcodeReader
                    {
                        Options = new DecodingOptions
                        {
                            PossibleFormats = new[] { BarcodeFormat.QR_CODE, BarcodeFormat.CODE_128 },
                            TryHarder = true
                        }
                    };
                }

                PhotoPreview.Source = _cameraCapture;
                await _cameraCapture.StartPreviewAsync();
                _cameraCapture.Failed += CameraCaptureOnFailed;
                _scannerAutoFocus = await ScannerAutoFocus.StartAsync(_cameraCapture.VideoDeviceController.FocusControl);
                _cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            }
            catch (Exception ex)
            {
                WindowsPhoneUtils.Log(ex.Message);
            }
            _bInitializingCamera = false;
        }
        async private void Start_Capture_Preview_Click()
        {
            //var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);
            var Videodevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var cameraDevice = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            if (cameraDevice == null)
            {
                Debug.WriteLine("No camera device found!");
                return;
            }

            // Create MediaCapture and its settings
            captureManager = new MediaCapture();

            var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };

            // Initialize MediaCapture
            try
            {
                await captureManager.InitializeAsync(settings);
                // just after initialization
                var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate(
                                    (i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
                await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
                captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                _isInitialized = true;                
            }
            catch (UnauthorizedAccessException)
            {
                Debug.WriteLine("The app was denied access to the camera");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString());
            }
            
            capturePreview.Source = captureManager;   //Start preiving on CaptureElement  
            await captureManager.StartPreviewAsync();  //Start camera capturing   
        }        
Example #17
0
        async void StartCamera()
        {
            var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
            mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id

            });
            //var maxResolution = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
            //await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);

            var maxResolution = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate(
                    (i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
            await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);

            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            //mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
            CameraPreview.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
        }
 private async void InitializePreview()
 {
     var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);
     if (cameraDevice == null)
     {
         Debug.WriteLine("No camera device found!");
         return;
     }
     capturePhotoManager = new MediaCapture();
     var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
     await capturePhotoManager.InitializeAsync(settings);
     capturePhotoManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
     PhotoPreview.Source = null;
     TakenImage.Source = null;
     StartPreview();
 }
Example #19
0
        private async Task CaptureImage()
        {

            cameraCapture = new MediaCapture();
            cameraCapture.Failed += cameraCapture_Failed;

            await cameraCapture.InitializeAsync();

#if WINDOWS_PHONE_APP
    cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
    cameraCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
#endif

            captureGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
            previewElement.Visibility = Windows.UI.Xaml.Visibility.Visible;
            previewElement.Source = cameraCapture;
            await cameraCapture.StartPreviewAsync();
        }
Example #20
0
        private async Task InitializeQrCode()
        {
            string error = null;
            try
            {
                //if (_mediaCapture == null)  
                //{  
                // Find all available webcams  
                DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);


                // Get the proper webcam (default one)  
                DeviceInformation backWebcam = (from webcam in webcamList where webcam.IsEnabled && webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back select webcam).FirstOrDefault();


                // Initializing MediaCapture  


                _mediaCapture = new MediaCapture();
                await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = backWebcam.Id,
                    AudioDeviceId = "",
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                });


                // Adjust camera rotation for Phone  
                _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                _mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);


                // Set the source of CaptureElement to MediaCapture  
                captureElement.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();


                //_mediaCapture.FocusChanged += _mediaCapture_FocusChanged;


                // Seetting Focus & Flash(if Needed)  


                var torch = _mediaCapture.VideoDeviceController.TorchControl;
                if (torch.Supported) torch.Enabled = true;


                await _mediaCapture.VideoDeviceController.FocusControl.UnlockAsync();
                var focusSettings = new FocusSettings();
                focusSettings.AutoFocusRange = AutoFocusRange.FullRange;
                focusSettings.Mode = FocusMode.Continuous;
                focusSettings.WaitForFocus = true;
                focusSettings.DisableDriverFallback = false;
                _mediaCapture.VideoDeviceController.FocusControl.Configure(focusSettings);
                await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();


                //}  
            }
            catch (Exception ex)
            {
                dialog = new MessageDialog("Error: " + ex.Message);
                dialog.ShowAsync();
            }
        }
        /// <summary>
        /// initializes the preview with our desired settings
        /// </summary>
        private async void InitializePreview()
        {
            captureManager = new MediaCapture();

            var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);

            await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id,
            });

            await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution());

            captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

            StartPreview();
        }
Example #22
0
		public async Task Initialise()
		{
			if (!_areWeInitialising)
			{
				_areWeInitialising = true;
				if (_mediaCaptureSettings == null) { await GenerateDefaults(); }
				if (_mediaCaptureSettings != null)
				{

					if (mediaCapture != null)
					{
						mediaCapture.Dispose();
					}
					mediaCapture = new MediaCapture();
					await mediaCapture.InitializeAsync(_mediaCaptureSettings);
					isFlashSupported = mediaCapture.VideoDeviceController.FlashControl.Supported;
					mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
					EnableFlash();
				}
			_areWeInitialising = false;
			}
		}
Example #23
0
        //private void orientView()
        //{
        //    var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
        //    grid.Height = bounds.Height;
        //    grid.Width = bounds.Width;

        //    var displayInfo = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
        //    switch (displayInfo.CurrentOrientation)
        //    {
        //        case Windows.Graphics.Display.DisplayOrientations.Landscape:
        //            mediaCapture.SetPreviewRotation(VideoRotation.None);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.LandscapeFlipped:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.Portrait:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.PortraitFlipped:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
        //            break;
        //    }
        //}

        async private void InitCamera()
        {
            if (App.APP_SETTINGS.Cameras.Count > 0)
            {
                try
                {
                    mediaCapture = new MediaCapture();
                    await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = App.APP_SETTINGS.Cameras[App.APP_SETTINGS.SelectedCamera].ID, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview, StreamingCaptureMode = StreamingCaptureMode.Video });
                    SetResolution();

                    capturePreview.Source = mediaCapture;
                    //orientView();

                    if(App.IsMobile)
                        mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

                    await mediaCapture.StartPreviewAsync();
                    if (mediaCapture.VideoDeviceController.FocusControl.Supported)
                    {
                        await mediaCapture.VideoDeviceController.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.AutoNormal);
                    }
                    else
                    {
                        FocusText.Visibility = Visibility.Collapsed;
                    }
             
                    if(!mediaCapture.VideoDeviceController.TorchControl.Supported)
                    {
                        btnTorch.Visibility = Visibility.Collapsed;
                    }
                    
                    beginCapture();
                }
                catch (Exception ex)
                {

                }
            }
            else
            {
                NoCamera.Visibility = Visibility.Visible;
            }
        }
        private async Task SwitchCameras(object sender, RoutedEventArgs e)
        {
            await mediaCaptureMgr.StopPreviewAsync();
            mediaCaptureMgr.Dispose();
            mediaCaptureMgr = null;
            mediaCaptureMgr = new MediaCapture();

            if (isUsingFrontCam)
            {
                await mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = rearCam.Id });

                mediaCaptureMgr.SetRecordRotation(VideoRotation.Clockwise90Degrees);
                mediaCaptureMgr.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            }
            else
            {
                await mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = frontCam.Id });

                mediaCaptureMgr.SetRecordRotation(VideoRotation.Clockwise270Degrees);
                mediaCaptureMgr.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
            }

            isUsingFrontCam = !isUsingFrontCam;

            StartPreview();
        }