Beispiel #1
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);
            });
        }
Beispiel #2
0
 private void CapturingCompletedAction(PhotoCaptureDelegate photoDelegate)
 {
     DispatchQueue.MainQueue.DispatchAsync(() =>
     {
         if (photoDelegate.PhotoData != null)
         {
             _photoCapturingDelegate?.DidCapturePhotoData(photoDelegate.PhotoData,
                                                          photoDelegate.RequestedPhotoSettings);
         }
         else if (photoDelegate.ProcessError != null)
         {
             _photoCapturingDelegate?.DidFailCapturingPhotoWith(photoDelegate.ProcessError);
         }
     });
 }