private async Task SelectFallbackSourceGroupAsync()
        {
#if USE_INFRARED
            var devices = await DeviceInformation.FindAllAsync(MediaFrameSourceGroup.GetDeviceSelector());

            foreach (var deviceInformation in devices)
            {
                var sourceGroup = await MediaFrameSourceGroup.FromIdAsync(deviceInformation.Id);

                var colorSourceInfos  = sourceGroup.SourceInfos.Where(sourceInfo => sourceInfo.SourceKind == MediaFrameSourceKind.Color);
                var enclosureLocation = colorSourceInfos.Select(sourceInfo => sourceInfo?.DeviceInformation?.EnclosureLocation).FirstOrDefault(enclosure => enclosure != null);

                if (colorSourceInfos.Any() &&
                    enclosureLocation.Panel == InfraredEnclosureLocation.Panel)
                {
                    FallbackSourceGroup    = sourceGroup;
                    ExclusiveRgbSourceInfo = colorSourceInfos.OrderByDescending(sourceInfo => sourceInfo?.MediaStreamType == ExclusiveIrSourceInfo.MediaStreamType).First();
                    ColorEnclosureLocation = enclosureLocation;
                    break;
                }
            }
#else
            SharedSourceInfo  = ExclusiveRgbSourceInfo;
            SharedSourceGroup = ExclusiveSourceGroup;
#endif
        }
 public CameraRotationHelper(EnclosureLocation cameraEnclosureLocation)
 {
     _cameraEnclosureLocation = cameraEnclosureLocation;
     if (!IsEnclosureLocationExternal(_cameraEnclosureLocation))
     {
         _orientationSensor.OrientationChanged += SimpleOrientationSensor_OrientationChanged;
     }
     _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged;
 }
 public CameraRotationHelper(EnclosureLocation cameraEnclosureLocation)
 {
     this.cameraEnclosureLocation = cameraEnclosureLocation;
     if (!IsEnclosureLocationExternal(this.cameraEnclosureLocation) && orientationSensor != null)
     {
         orientationSensor.OrientationChanged += SimpleOrientationSensor_OrientationChanged;
     }
     displayInformation.OrientationChanged += DisplayInformation_OrientationChanged;
 }
Beispiel #4
0
        private void InitializeCapturePreview(EnclosureLocation cameraLocation)
        {
            if (cameraLocation != null && cameraLocation.Panel == Windows.Devices.Enumeration.Panel.Front)
            {
                _capturePreview.FlowDirection = FlowDirection.RightToLeft;
            }

            _capturePreview.Source = _mediaCapture;
        }
        public void SetCameraEnclosureLocation(EnclosureLocation cameraEnclosureLocation)
        {
            _displayInformation = DisplayInformation.GetForCurrentView();
            _orientationSensor  = SimpleOrientationSensor.GetDefault();

            _cameraEnclosureLocation = cameraEnclosureLocation;
            if (!IsEnclosureLocationExternal(_cameraEnclosureLocation) && _orientationSensor != null)
            {
                _orientationSensor.OrientationChanged += SimpleOrientationSensor_OrientationChanged;
            }
            _displayInformation.OrientationChanged += DisplayInformation_OrientationChanged;
        }
 public static bool IsEnclosureLocationExternal(EnclosureLocation enclosureLocation)
 {
     return(enclosureLocation == null || enclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown);
 }
Beispiel #7
0
        private async void Camera_Click(object sender, RoutedEventArgs e)
        {
            if (isPreviewing)
            {
                CameraControl.Visibility = Visibility.Collapsed;
                LowLagPhotoCapture lowLagCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(
                    ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));

                CapturedPhoto capturedPhoto = await lowLagCapture.CaptureAsync();

                SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
                if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 ||
                    softwareBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
                {
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap,
                                                            BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }

                var source = new SoftwareBitmapSource();
                await source.SetBitmapAsync(softwareBitmap);

                Job j = DataContext as Job;
                if (j != null)
                {
                    j.Photo = softwareBitmap;
                }

                await lowLagCapture.FinishAsync();
                await CleanupCameraAsync();

                isPreviewing = false;
            }
            else
            {
                CameraControl.Visibility = Visibility.Visible;

                try
                {
                    MediaCaptureInitializationSettings mediaInitSettings =
                        new MediaCaptureInitializationSettings();

                    DeviceInformationCollection devices =
                        await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                    foreach (var device in devices)
                    {
                        EnclosureLocation loc = device.EnclosureLocation;
                        Debug.WriteLine($"Location: {loc.Panel.ToString()} ID: {device.Id}");
                        if (sender is Button &&
                            ((Button)sender).Tag.ToString() == loc.Panel.ToString())
                        {
                            mediaInitSettings.VideoDeviceId        = device.Id;
                            mediaInitSettings.StreamingCaptureMode = StreamingCaptureMode.Video;
                            mediaInitSettings.PhotoCaptureSource   = PhotoCaptureSource.VideoPreview;


                            break;
                        }
                    }

                    mediaCapture = new MediaCapture();
                    await mediaCapture.InitializeAsync(mediaInitSettings);

                    var resolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(
                        MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
                    var minRes = resolutions.OrderBy(x => x.Height * x.Width).FirstOrDefault();
                    await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(
                        MediaStreamType.VideoPreview, minRes);

                    PreviewControl.Source = mediaCapture;
                    await mediaCapture.StartPreviewAsync();

                    isPreviewing = true;

                    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);
                }
            }
        }