protected void TakePicture()
        {
            var session = _cameraPreview.CaptureSession;
            var output  = session.Outputs[0] as AVCapturePhotoOutput;
            //output.IsHighResolutionCaptureEnabled = true;

            var photoSettings = AVCapturePhotoSettings.Create();

            photoSettings.IsAutoStillImageStabilizationEnabled = true;
            //photoSettings.IsHighResolutionPhotoEnabled = true;

            var flashModeAuto = output?.SupportedFlashModes.Contains(_flashModeAutoFlash) ?? false;

            if (flashModeAuto == true)
            {
                photoSettings.FlashMode = AVCaptureFlashMode.Auto;
            }

            if (photoSettings.AvailablePreviewPhotoPixelFormatTypes.Length > 0)
            {
                photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, output.AvailablePhotoPixelFormatTypes[0]);
            }

            var photoCaptureDelegate = new PhotoCaptureDelegate();

            photoCaptureDelegate.PictureTaken += OnPictureTaken;

            output.CapturePhoto(photoSettings, photoCaptureDelegate);
        }
Esempio n. 2
0
 private void WillCapturePhotoAnimationAction(AVCapturePhotoSettings photoSettings)
 {
     DispatchQueue.MainQueue.DispatchAsync(() =>
     {
         _photoCapturingDelegate.WillCapturePhotoWith(photoSettings);
     });
 }
Esempio n. 3
0
        private void CapturePhoto()
        {
            var photoSettings = AVCapturePhotoSettings.Create();

            photoSettings.IsHighResolutionPhotoEnabled = true;
            _photoOutput.CapturePhoto(photoSettings, this);
        }
        private void CapturePhoto(object sender, EventArgs e)
        {
            ToogleButtons(false);
            var settingKeys = new object[]
            {
                AVVideo.CodecKey,
                AVVideo.CompressionPropertiesKey,
            };

            var settingObjects = new object[]
            {
                new NSString("jpeg"),
                new NSDictionary(AVVideo.QualityKey, 1),
            };

            var settingsDictionary = NSDictionary <NSString, NSObject> .FromObjectsAndKeys(settingObjects, settingKeys);

            var settings = AVCapturePhotoSettings.FromFormat(settingsDictionary);

            if (_capturePhotoOutput.SupportedFlashModes.Length > 0 && _captureDeviceInput.Device.Position == AVCaptureDevicePosition.Back)
            {
                settings.FlashMode = _flashMode;
            }

            orientationOnPhoto = currentOrientation;
            _capturePhotoOutput.CapturePhoto(settings, this);
        }
Esempio n. 5
0
        private void CapturePhoto(object sender, EventArgs e)
        {
            var settingKeys = new object[]
            {
                AVVideo.CodecKey,
                AVVideo.CompressionPropertiesKey,
            };

            var settingObjects = new object[]
            {
                new NSString("jpeg"),
                new NSDictionary(AVVideo.QualityKey, 0.5),
            };

            var settingsDictionary = NSDictionary <NSString, NSObject> .FromObjectsAndKeys(settingObjects, settingKeys);

            var settings = AVCapturePhotoSettings.FromFormat(settingsDictionary);

            if (_captureDeviceInput.Device.Position == AVCaptureDevicePosition.Back)
            {
                settings.FlashMode = AVCaptureFlashMode.Auto;
            }

            _capturePhotoOutput.CapturePhoto(settings, this);
        }
Esempio n. 6
0
 public AVCamPhotoCaptureDelegate(AVCapturePhotoSettings requestedPhotoSettings, Action willCapturePhotoAnimation, Action <bool> livePhotoCaptureHandler, Action <AVCamPhotoCaptureDelegate> completionHandler)
 {
     RequestedPhotoSettings    = requestedPhotoSettings;
     WillCapturePhotoAnimation = willCapturePhotoAnimation;
     LivePhotoCaptureHandler   = livePhotoCaptureHandler;
     CompletionHandler         = completionHandler;
 }
Esempio n. 7
0
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error         = new NSError();
            var photoSettings = AVCapturePhotoSettings.Create();

            photoSettings.FlashMode = AVCaptureFlashMode.Auto;
            photoSettings.IsHighResolutionPhotoEnabled = true;

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            else if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                device.UnlockForConfiguration();
            }
            else if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
            {
                device.LockForConfiguration(out error);
                device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
                device.UnlockForConfiguration();
            }
        }
Esempio n. 8
0
 public void DidCapturePhotoData(NSData didCapturePhotoData,
                                 AVCapturePhotoSettings settings)
 {
     Console.WriteLine($"did capture photo {settings.UniqueID}");
     _imagePickerControllerDelegate?.DidTake(UIImage.LoadFromData(didCapturePhotoData));
     didCapturePhotoData.Dispose();
 }
 public PhotoCaptureDelegate(AVCapturePhotoSettings requestedPhotoSettings,
                             Action willCapturePhotoAnimation,
                             Action <bool> capturingLivePhoto,
                             Action <PhotoCaptureDelegate> completed)
 {
     RequestedPhotoSettings  = requestedPhotoSettings;
     this.capturingLivePhoto = capturingLivePhoto;
     this.completed          = completed;
 }
		public PhotoCaptureDelegate (AVCapturePhotoSettings settings,
									 Action willCapturePhotoAnimation,
									 Action<bool> capturingLivePhoto,
									 Action<PhotoCaptureDelegate> completed)
		{
			RequestedPhotoSettings = settings;
			this.willCapturePhotoAnimation = willCapturePhotoAnimation;
			this.capturingLivePhoto = capturingLivePhoto;
			this.completed = completed;
		}
Esempio n. 11
0
        private static AVCapturePhotoSettings CreatePhotoSettings()
        {
            var photoSettings =
                AVCapturePhotoSettings.FromFormat(
                    new NSDictionary <NSString, NSObject>(AVVideo.CodecKey, AVVideoCodecType.Jpeg.GetConstant()));

            photoSettings.IsHighResolutionPhotoEnabled         = true;
            photoSettings.IsAutoStillImageStabilizationEnabled = true;
            return(photoSettings);
        }
Esempio n. 12
0
        public PhotoCaptureDelegate(AVCapturePhotoSettings requestedPhotoSettings, Action willCapturePhotoAnimation,
                                    Action <bool> capturingLivePhoto, Action <PhotoCaptureDelegate> completed)
        {
            RequestedPhotoSettings     = requestedPhotoSettings;
            _willCapturePhotoAnimation = willCapturePhotoAnimation;
            _capturingLivePhoto        = capturingLivePhoto;
            _completed = completed;

            ShouldSavePhotoToLibrary = true;
        }
Esempio n. 13
0
        public void HandleAction()
        {
            var photoSettings    = AVCapturePhotoSettings.Create();
            var photoPreviewType = photoSettings.AvailablePreviewPhotoPixelFormatTypes.First();

            if (photoPreviewType != null)
            {
                photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, photoPreviewType);
                _photoOutput.CapturePhoto(photoSettings, this);
            }
        }
Esempio n. 14
0
        /// <summary
        /// <summary>
        /// 写真撮影をします。
        /// </summary>
        public async static Task TakePhoto()
        {
            // カメラの設定
            PhotoSettings = AVCapturePhotoSettings.Create();
            PhotoSettings.DepthDataFiltered = false;

            var CaptureDelegate = new PhotoCaptureDelegate();
            // 写真の撮影
            await Task.Run(() =>
            {
                PhotoOutput.CapturePhoto(PhotoSettings, CaptureDelegate);
            });
        }
Esempio n. 15
0
        private async void CapturePhoto()
        {
            try
            {
                if (_is10OrHigher)
                {
                    var photoSettings = AVCapturePhotoSettings.Create();
                    photoSettings.IsHighResolutionPhotoEnabled = true;
                    _photoOutput.CapturePhoto(photoSettings, this);
                }
                else
                {
                    var videoConnection = _stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
                    var sampleBuffer    = await _stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

                    if (_cameraModule.BluetoothOperator.IsPrimary ||
                        _cameraModule.BluetoothOperator.PairStatus != PairStatus.Connected)
                    {
                        _cameraModule.CaptureSuccess = !_cameraModule.CaptureSuccess;
                    }

                    if (!(_cameraModule.BluetoothOperator.PairStatus == PairStatus.Connected &&
                          !_cameraModule.BluetoothOperator.IsPrimary))
                    {
                        LockPictureSpecificSettingsIfApplicable();
                    }

                    var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
                    using (var image = UIImage.LoadFromData(jpegImageAsNsData))
                        using (var cgImage = image.CGImage)
                            using (var rotatedImage = UIImage.FromImage(cgImage, 1, GetOrientationForCorrection()))
                            {
                                var imageBytes = rotatedImage.AsJPEG().ToArray();
                                if (_cameraModule.BluetoothOperator.PairStatus == PairStatus.Connected &&
                                    !_cameraModule.BluetoothOperator.IsPrimary)
                                {
                                    _cameraModule.BluetoothOperator.SendCapture(imageBytes);
                                }
                                else
                                {
                                    _cameraModule.CapturedImage = imageBytes;
                                }
                            }
                }
            }
            catch (Exception e)
            {
                _cameraModule.ErrorMessage = e.ToString();
            }
        }
Esempio n. 16
0
        public void CaptureMovie()
        {
            //start recording

            if (!isRecording && CameraMode == CameraModes.Video)
            {
                var outputUrl = ApplicationDocumentsDirectory().Append($"Video_{DateTime.Now.ToString("yyMMdd_hhmmss")}", false).AppendPathExtension("mov");
                VideoFileUrl = outputUrl.AbsoluteString;
                // string localFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
                // var localPath = System.IO.Path.Combine(localFolder, $"Video_{DateTime.Now.ToString("yyMMdd_hhmmss")}.mov");
                //  var outputUrl = ApplicationDocumentsDirectory().Append($"Video_{DateTime.Now.ToString("yyMMdd-hhmmss")}", false).AppendPathExtension("mov");
                var _delegate = new OutputRecorder();
                _delegate.SavedMovie += (sender, e) =>
                {
                    Video?.Invoke(this, VideoFileUrl);
                    /// SavedMovie(this, new ListEventArgs(outputUrl.AbsoluteString, e.error?.LocalizedDescription));
                    //Analytics.TrackEvent("Trigger seconds SavedMovie Event");
                };
                movieFileOutput.StartRecordingToOutputFile(outputUrl, _delegate);
                //takePhotoButton.Hidden = true;
                //stopRecordButton.Hidden = false;
                StartedRecordingVideo?.Invoke(this, EventArgs.Empty);
            }
            else if (isRecording && CameraMode == CameraModes.Video)
            {
                movieFileOutput.StopRecording();
                //takePhotoButton.Hidden = false;
                //stopRecordButton.Hidden = true;
            }
            else if (CameraMode == CameraModes.Snapshot)
            {
                var cb = new PhotoRecorderDelegate();
                cb.SavedPhoto += (object sender, ListEventArgs e) =>
                {
                    /// SavedMovie(this, e);
                    PhotoPath?.Invoke(this, e.MovieUrl);
                };
                var dictionary = new NSDictionary <NSString, NSObject>
                                 (
                    AVVideo.CodecKey, AVVideo.CodecJPEG
                                 );
                var setting = AVCapturePhotoSettings.FromFormat(dictionary);
                setting.IsHighResolutionPhotoEnabled         = true;
                setting.IsAutoStillImageStabilizationEnabled = true;
                photoFileOutput.CapturePhoto(setting, cb);
            }

            isRecording = !isRecording;
        }
Esempio n. 17
0
        public void CapturePhoto(LivePhotoMode livePhotoMode, bool saveToPhotoLibrary)
        {
            _sessionQueue.DispatchAsync(() =>
            {
                var photoSettings = AVCapturePhotoSettings.Create();

                if (_photoOutput.SupportedFlashModes.Contains(NSNumber.FromInt32((int)AVCaptureFlashMode.Auto)))
                {
                    photoSettings.FlashMode = AVCaptureFlashMode.Auto;
                }

                photoSettings.IsHighResolutionPhotoEnabled = true;

                var availablePhotoCodecTypes = photoSettings.AvailableEmbeddedThumbnailPhotoCodecTypes;

                if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0) && availablePhotoCodecTypes.Length > 0)
                {
                    photoSettings.EmbeddedThumbnailPhotoFormat = new NSMutableDictionary
                    {
                        { AVVideo.CodecKey, availablePhotoCodecTypes[0].GetConstant() }
                    };
                }

                if (livePhotoMode == LivePhotoMode.On)
                {
                    if (_presetConfiguration == SessionPresetConfiguration.LivePhotos &&
                        _photoOutput.IsLivePhotoCaptureSupported)
                    {
                        photoSettings.LivePhotoMovieFileUrl =
                            NSUrl.CreateFileUrl(new[] { Path.GetTempPath(), $"{Guid.NewGuid()}.mov" });
                    }
                    else
                    {
                        Console.WriteLine(
                            "capture session: warning - trying to capture live photo but it's not supported by current configuration, capturing regular photo instead");
                    }
                }

                // Use a separate object for the photo capture delegate to isolate each capture life cycle.
                var photoCaptureDelegate = new PhotoCaptureDelegate(photoSettings,
                                                                    () => WillCapturePhotoAnimationAction(photoSettings),
                                                                    CapturingLivePhotoAction, CapturingCompletedAction)
                {
                    ShouldSavePhotoToLibrary = saveToPhotoLibrary
                };

                _photoOutput.CapturePhoto(photoSettings, photoCaptureDelegate);
            });
        }
Esempio n. 18
0
        private void HandleCapture()
        {
            if (captureOutput == null)
            {
                return;
            }

            var photoSettings = AVCapturePhotoSettings.Create();

            photoSettings.IsAutoStillImageStabilizationEnabled = true;
            photoSettings.IsHighResolutionPhotoEnabled         = true;
            photoSettings.FlashMode = flashMode;

            captureOutput.CapturePhoto(photoSettings, this);
        }
Esempio n. 19
0
        public void Capture()
        {
            // Create Photo Settings
            photoSettings = AVCapturePhotoSettings.FromFormat(new NSDictionary <NSString, NSObject>(AVVideo.CodecKey, AVVideo.CodecJPEG));
            photoSettings.IsHighResolutionPhotoEnabled = true;
            photoSettings.IsDepthDataDeliveryEnabled(false);

            if (photoSettings.AvailablePreviewPhotoPixelFormatTypes.Count() > 0)
            {
                photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, photoSettings.AvailablePreviewPhotoPixelFormatTypes.First());
            }

            // Use a separate object for the photo capture delegate to isolate each capture life cycle.
            photoCaptureDelegate = new XCameraPhotoCaptureDelegate(photoSettings, PhotoCapturedHandler);

            photoOutput.CapturePhoto(photoSettings, photoCaptureDelegate);
        }
Esempio n. 20
0
        partial void TakePhoto(UIButton sender)
        {
            AVCaptureVideoOrientation layerOrientation = videoPreviewLayer.Connection.VideoOrientation;

            if (isMovie)
            {
                ShutterButton.Enabled = false; // disable until recording starts/stops

                if (!movieOutput.Recording)
                {
                    // set up recording
                    if (UIDevice.CurrentDevice.IsMultitaskingSupported)
                    {
                        backgroundRecordingId = UIApplication.SharedApplication.BeginBackgroundTask(null);
                    }

                    AVCaptureConnection connection = movieOutput?.ConnectionFromMediaType(AVMediaType.Video);
                    if (connection != null)
                    {
                        connection.VideoOrientation = layerOrientation;
                    }

                    SetPaths(".mov");

                    movieOutput.StartRecordingToOutputFile(NSUrl.FromFilename(filePath), this);
                }
                else
                {
                    // finish recording
                    movieOutput.StopRecording();
                }
            }
            else
            {
                AVCapturePhotoSettings photoSettings = AVCapturePhotoSettings.Create();

                // The first format in the array is the preferred format
                if (photoSettings.AvailablePreviewPhotoPixelFormatTypes.Length > 0)
                {
                    photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, photoSettings.AvailablePreviewPhotoPixelFormatTypes[0]);
                }

                stillImageOutput.CapturePhoto(photoSettings, this);
            }
        }
Esempio n. 21
0
 void HandleButtonClick()
 {
     ToggleBusy(true);
     if (OCRButton.TitleLabel.Text == "Take Picture")
     {
         using (var settings = AVCapturePhotoSettings.Create())
         {
             ImageOutput.CapturePhoto(settings, Camera);
         }
         OCRButton.SetTitle("Retake Picture", UIControlState.Normal);
     }
     else
     {
         PictureView.Image = null;
         Capture           = null;
         OCRButton.SetTitle("Take Picture", UIControlState.Normal);
         ToggleBusy(false);
     }
 }
        public async Task CapturePhotoAsync(string path)
        {
            var settings = AVCapturePhotoSettings.FromFormat(NSDictionary <NSString, NSObject> .FromObjectsAndKeys(
                                                                 new object[]
            {
                AVVideo.CodecJPEG,
                new NSDictionary(AVVideo.QualityKey, 0.9)
            },
                                                                 new object[]
            {
                AVVideo.CodecKey,
                AVVideo.CompressionPropertiesKey
            }));

            _photoCapturePath = path;
            photoOutput.CapturePhoto(settings, this);
            while (_photoCapturePath != null)
            {
                await Task.Yield();
            }
        }
Esempio n. 23
0
        private void CapturePhoto(object sender, EventArgs e)
        {
            var settingKeys = new object[]
            {
                AVVideo.CodecKey,
                AVVideo.CompressionPropertiesKey,
            };

            var settingObjects = new object[]
            {
                new NSString("jpeg"),
                new NSDictionary(AVVideo.QualityKey, 0.5),
            };

            var settingsDictionary = NSDictionary <NSString, NSObject> .FromObjectsAndKeys(settingObjects, settingKeys);

            var settings = AVCapturePhotoSettings.FromFormat(settingsDictionary);

            settings.FlashMode = AVCaptureFlashMode.Auto;

            //_photoOrientation = UIDevice.CurrentDevice.Orientation;
            _capturePhotoOutput.CapturePhoto(settings, this);
        }
Esempio n. 24
0
        void CapturePhoto(NSObject sender)
        {
            /*
             *      Retrieve the video preview layer's video orientation on the main queue before
             *      entering the session queue. We do this to ensure UI elements are accessed on
             *      the main thread and session configuration is done on the session queue.
             */
            var videoPreviewLayerVideoOrientation = VideoPreviewLayer.Connection.VideoOrientation;

            sessionQueue.DispatchAsync(() =>
            {
                // Update the photo output's connection to match the video orientation of the video preview layer.
                var photoOutputConnection = photoOutput.ConnectionFromMediaType(AVMediaType.Video);
                photoOutputConnection.VideoOrientation = videoPreviewLayerVideoOrientation;

                AVCapturePhotoSettings photoSettings;
                // Capture HEIF photo when supported, with flash set to auto and high resolution photo enabled.

                if (photoOutput.AvailablePhotoCodecTypes.Where(codec => codec == AVVideo2.CodecHEVC).Any())
                {
                    photoSettings = AVCapturePhotoSettings.FromFormat(new NSDictionary <NSString, NSObject>(AVVideo.CodecKey, AVVideo2.CodecHEVC));
                }
                else
                {
                    photoSettings = AVCapturePhotoSettings.Create();
                }

                if (videoDeviceInput.Device.FlashAvailable)
                {
                    photoSettings.FlashMode = AVCaptureFlashMode.Auto;
                }
                photoSettings.IsHighResolutionPhotoEnabled = true;
                if (photoSettings.AvailablePreviewPhotoPixelFormatTypes.Count() > 0)
                {
                    photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CoreVideo.CVPixelBuffer.PixelFormatTypeKey, photoSettings.AvailablePreviewPhotoPixelFormatTypes.First());
                }
                if (livePhotoMode == AVCamLivePhotoMode.On && photoOutput.IsLivePhotoCaptureSupported)
                {
                    // Live Photo capture is not supported in movie mode.
                    var livePhotoMovieFileName          = Guid.NewGuid().ToString();
                    var livePhotoMovieFilePath          = NSFileManager.DefaultManager.GetTemporaryDirectory().Append($"{livePhotoMovieFileName}.mov", false);
                    photoSettings.LivePhotoMovieFileUrl = livePhotoMovieFilePath;
                }

                if (depthDataDeliveryMode == AVCamDepthDataDeliveryMode.On && photoOutput.IsDepthDataDeliverySupported())
                {
                    photoSettings.IsDepthDataDeliveryEnabled(true);
                }
                else
                {
                    photoSettings.IsDepthDataDeliveryEnabled(false);
                }

                // Use a separate object for the photo capture delegate to isolate each capture life cycle.
                var photoCaptureDelegate = new AVCamPhotoCaptureDelegate(photoSettings, () =>
                {
                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        VideoPreviewLayer.Opacity = 0.0f;
                        UIView.Animate(0.25, () =>
                        {
                            VideoPreviewLayer.Opacity = 1.0f;
                        });
                    });
                }, (bool capturing) =>
                {
                    /*
                     *      Because Live Photo captures can overlap, we need to keep track of the
                     *      number of in progress Live Photo captures to ensure that the
                     *      Live Photo label stays visible during these captures.
                     */
                    sessionQueue.DispatchAsync(() =>
                    {
                        if (capturing)
                        {
                            inProgressLivePhotoCapturesCount++;
                        }
                        else
                        {
                            inProgressLivePhotoCapturesCount--;
                        }

                        var lInProgressLivePhotoCapturesCount = inProgressLivePhotoCapturesCount;
                        //DispatchQueue.MainQueue.DispatchAsync(() =>
                        //{
                        //	if (lInProgressLivePhotoCapturesCount > 0)
                        //	{
                        //		CapturingLivePhotoLabel.Hidden = false;
                        //	}
                        //	else if (lInProgressLivePhotoCapturesCount == 0)
                        //	{
                        //		CapturingLivePhotoLabel.Hidden = true;
                        //	}
                        //	else
                        //	{
                        //		Console.WriteLine(@"Error: In progress live photo capture count is less than 0");
                        //	}
                        //});
                    });
                }, (AVCamPhotoCaptureDelegate lPhotoCaptureDelegate) =>
                {
                    // When the capture is complete, remove a reference to the photo capture delegate so it can be deallocated.
                    sessionQueue.DispatchAsync(() =>
                    {
                        inProgressPhotoCaptureDelegates[lPhotoCaptureDelegate.RequestedPhotoSettings.UniqueID] = null;
                    });
                });

                /*
                 *      The Photo Output keeps a weak reference to the photo capture delegate so
                 *      we store it in an array to maintain a strong reference to this object
                 *      until the capture is completed.
                 */
                inProgressPhotoCaptureDelegates[photoCaptureDelegate.RequestedPhotoSettings.UniqueID] = photoCaptureDelegate;
                photoOutput.CapturePhoto(photoSettings, photoCaptureDelegate);
            });
        }
Esempio n. 25
0
 public void CapturePhoto(AVCapturePhotoSettings settings)
 {
 }
 public XCameraPhotoCaptureDelegate(AVCapturePhotoSettings requestedPhotoSettings, Action <byte[]> completionHandler)
 {
     RequestedPhotoSettings = requestedPhotoSettings;
     CompletionHandler      = completionHandler;
 }
Esempio n. 27
0
 public static string ProcessedFileType(this AVCapturePhotoSettings This)
 {
     return(NSString.FromHandle(global::ApiDefinition.Messaging.IntPtr_objc_msgSend(This.Handle, Selector.GetHandle("processedFileType"))));
 }
Esempio n. 28
0
 public static void IsDepthDataDeliveryEnabled(this AVCapturePhotoSettings This, bool enabled)
 {
     global::ApiDefinition.Messaging.void_objc_msgSend_bool(This.Handle, Selector.GetHandle("setDepthDataDeliveryEnabled:"), enabled);
 }
Esempio n. 29
0
 public static bool IsDepthDataDeliveryEnabled(this AVCapturePhotoSettings This)
 {
     return(global::ApiDefinition.Messaging.bool_objc_msgSend(This.Handle, Selector.GetHandle("isDepthDataDeliveryEnabled")));
 }
Esempio n. 30
0
        void CapturePhoto()
        {
            // Retrieve the video preview layer's video orientation on the main queue before
            // entering the session queue. We do this to ensure UI elements are accessed on
            // the main thread and session configuration is done on the session queue.
            var videoPreviewLayerOrientation = PreviewView.VideoPreviewLayer.Connection.VideoOrientation;

            sessionQueue.DispatchAsync(() => {
                // Update the photo output's connection to match the video orientation of the video preview layer.
                var photoOutputConnection = photoOutput.ConnectionFromMediaType(AVMediaType.Video);
                if (photoOutputConnection != null)
                {
                    photoOutputConnection.VideoOrientation = videoPreviewLayerOrientation;
                }

                // Capture a JPEG photo with flash set to auto and high resolution photo enabled.
                var photoSettings       = AVCapturePhotoSettings.Create();
                photoSettings.FlashMode = (videoDeviceInput.Device.HasFlash) ? AVCaptureFlashMode.Auto : AVCaptureFlashMode.Off;
                photoSettings.IsHighResolutionPhotoEnabled = true;
                // TODO: request strong typed API
                if (photoSettings.AvailablePreviewPhotoPixelFormatTypes.Length > 0)
                {
                    photoSettings.PreviewPhotoFormat = new NSDictionary <NSString, NSObject>(CVPixelBuffer.PixelFormatTypeKey, photoOutput.AvailablePhotoPixelFormatTypes[0]);
                }
                // Live Photo capture is not supported in movie mode.
                if (livePhotoMode == LivePhotoMode.On && photoOutput.IsLivePhotoCaptureSupported)
                {
                    var livePhotoMovieFileName          = new NSUuid().AsString();
                    var livePhotoMovieFilePath          = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(livePhotoMovieFileName, "mov"));
                    photoSettings.LivePhotoMovieFileUrl = NSUrl.FromFilename(livePhotoMovieFilePath);
                }

                // Use a separate object for the photo capture delegate to isolate each capture life cycle.
                var photoCaptureDelegate = new PhotoCaptureDelegate(photoSettings, () => DispatchQueue.MainQueue.DispatchAsync(() => {
                    PreviewView.VideoPreviewLayer.Opacity = 0;
                    UIView.Animate(0.25, () => PreviewView.VideoPreviewLayer.Opacity = 1);
                }), capturing => {
                    // Because Live Photo captures can overlap, we need to keep track of the
                    // number of in progress Live Photo captures to ensure that the
                    // Live Photo label stays visible during these captures.
                    sessionQueue.DispatchAsync(() => {
                        if (capturing)
                        {
                            inProgressLivePhotoCapturesCount += 1;
                        }
                        else
                        {
                            inProgressLivePhotoCapturesCount -= 1;
                        }

                        var count = inProgressLivePhotoCapturesCount;
                        DispatchQueue.MainQueue.DispatchAsync(() => {
                            if (count > 0)
                            {
                                CapturingLivePhotoLabel.Hidden = false;
                            }
                            else if (count == 0)
                            {
                                CapturingLivePhotoLabel.Hidden = true;
                            }
                            else
                            {
                                Console.WriteLine("Error: In progress live photo capture count is less than 0");
                            }
                        });
                    });
                }, photoDelegate => {
                    // When the capture is complete, remove a reference to the photo capture delegate so it can be deallocated.
                    sessionQueue.DispatchAsync(() => inProgressPhotoCaptureDelegates.Remove(photoDelegate.RequestedPhotoSettings.UniqueID));
                });

                // The Photo Output keeps a weak reference to the photo capture delegate so
                // we store it in an array to maintain a strong reference to this object
                // until the capture is completed.
                inProgressPhotoCaptureDelegates[photoCaptureDelegate.RequestedPhotoSettings.UniqueID] = photoCaptureDelegate;
                photoOutput.CapturePhoto(photoSettings, photoCaptureDelegate);
            });
        }
Esempio n. 31
0
 public void WillCapturePhotoWith(AVCapturePhotoSettings settings)
 {
     Console.WriteLine($"will capture photo {settings.UniqueID}");
 }