public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { var jpegData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); var h = UIImage.LoadFromData(jpegData); GoToDescription(h); }
public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CoreMedia.CMSampleBuffer photoSampleBuffer, CoreMedia.CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { var imageData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); if (imageData != null) { var capturedImage = new UIImage(imageData); var storyboard = UIStoryboard.FromName("Main", NSBundle.MainBundle); UIViewController vc = new UIViewController(); if (came_from == Constants.personal) { CropCameraViewController.currentImage = capturedImage; vc = storyboard.InstantiateViewController(nameof(CropCameraViewController)); } else if (came_from == Constants.company_logo) { CropCompanyLogoViewController.currentImage = capturedImage; vc = storyboard.InstantiateViewController(nameof(CropCompanyLogoViewController)); } this.NavigationController.PushViewController(vc, true); } }
/// <summary> /// 初期化処理 /// </summary> private void Initialize() { previewLayer = new AVCaptureVideoPreviewLayer(CaptureSession) { Frame = Bounds, VideoGravity = AVLayerVideoGravity.ResizeAspectFill, }; AVCaptureDevice[] videoDevices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video); AVCaptureDevicePosition cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; device = videoDevices.FirstOrDefault(d => d.Position == cameraPosition); //キャプチャデバイスの生成に失敗している場合エラー if (device == null) { Console.WriteLine("CameraStartup Error"); return; } var input = new AVCaptureDeviceInput(device, out NSError error); CaptureSession.AddInput(input); // カメラの映像表示設定 Layer.AddSublayer(previewLayer); // 映像出力設定後、少しだけ待機 Thread.Sleep(300); // 出力開始 CaptureSession.StartRunning(); IsPreviewing = true; // キャプチャー出力設定 PhotoOutput = new AVCapturePhotoOutput(); CaptureSession.AddOutput(PhotoOutput); }
public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer == null || error != null) { Console.WriteLine("Error taking photo: " + error); return; } NSData imageData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); SetPaths(".jpg"); UIImage formattedImg = AppUtils.ScaleAndRotateImage(UIImage.LoadFromData(imageData)); imageData = formattedImg.AsJPEG(0.8f); if (imageData.Save(filePath, false, out NSError saveErr)) { Console.WriteLine("Saved photo to: " + filePath); ReturnWithData(innerPath); } else { Console.WriteLine("ERROR saving to " + fileName + " because " + saveErr.LocalizedDescription); } }
private void InitDevice() { captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); AVCaptureDeviceInput input; try { input = new AVCaptureDeviceInput(captureDevice, out NSError err); if (err == null) { captureSession = new AVCaptureSession(); captureSession.AddInput(input); previewLayer = new AVCaptureVideoPreviewLayer(captureSession) { VideoGravity = AVLayerVideoGravity.ResizeAspectFill, Frame = previewView.Layer.Bounds }; previewView.Layer.AddSublayer(previewLayer); captureOutput = new AVCapturePhotoOutput { IsHighResolutionCaptureEnabled = true }; captureSession.AddOutput(captureOutput); captureSession.StartRunning(); } } catch (Exception ex) { allowAndBack(); } }
public void DidFinishProcessingPhoto (AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer != null) photoData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation (photoSampleBuffer, previewPhotoSampleBuffer); else Console.WriteLine ($"Error capturing photo: {error.LocalizedDescription}"); }
public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) {/* * try * { * using (var pixelBuffer = photoSampleBuffer.GetImageBuffer() as CVPixelBuffer) * { * pixelBuffer.Lock(CVPixelBufferLock.None); * var j = CIImage.FromImageBuffer(pixelBuffer); * pixelBuffer.Unlock(CVPixelBufferLock.None); * } * * using(var t = photoSampleBuffer.GetImageBuffer()) * { * * } * * * //var i = new CGAffineTransform(); * //i.Rotate(90); * * //u = lol.ImageByApplyingTransform(y); * * //var filter = CIFilter.GetFilter("CIAffineTransform", ); * * * } * catch(Exception ex) * { * * }*/ var jpegData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); var h = UIImage.LoadFromData(jpegData); GoToDescription(h); }
public override void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer == null) { Console.WriteLine($"Error capturing photo: {error.LocalizedDescription}"); } }
#pragma warning restore CS4014 private void SetupLiveCameraStream() { captureSession = new AVCaptureSession(); var viewLayer = CameraFeedView.Layer; videoPreviewLayer = new AVCaptureVideoPreviewLayer(captureSession) { Frame = CameraFeedView.Frame, VideoGravity = AVLayerVideoGravity.ResizeAspectFill }; CameraFeedView.Layer.AddSublayer(videoPreviewLayer); AVCaptureDevice captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); ConfigureCameraForDevice(captureDevice); captureDeviceInput = AVCaptureDeviceInput.FromDevice(captureDevice); captureSession.AddInput(captureDeviceInput); if (isMovie) { // Add audio var audioDevice = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Audio); var audioDeviceInput = AVCaptureDeviceInput.FromDevice(audioDevice, out NSError audioErr); if (audioErr != null) { Console.WriteLine("Couldn't create audio device input: " + audioErr.LocalizedDescription); } if (captureSession.CanAddInput(audioDeviceInput)) { captureSession.AddInput(audioDeviceInput); } else { Console.WriteLine("Couldn't add audio input to session"); } movieOutput = new AVCaptureMovieFileOutput(); captureSession.AddOutput(movieOutput); captureSession.SessionPreset = AVCaptureSession.Preset1280x720; var connection = movieOutput.ConnectionFromMediaType(AVMediaType.Video); if (connection != null && connection.SupportsVideoStabilization) { connection.PreferredVideoStabilizationMode = AVCaptureVideoStabilizationMode.Auto; } captureSession.CommitConfiguration(); } else { stillImageOutput = new AVCapturePhotoOutput(); stillImageOutput.IsHighResolutionCaptureEnabled = true; stillImageOutput.IsLivePhotoCaptureEnabled = false; captureSession.AddOutput(stillImageOutput); captureSession.CommitConfiguration(); } ShutterButton.Hidden = false; captureSession.StartRunning(); }
public void WillBeginCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings) { if (resolvedSettings.LivePhotoMovieDimensions.Width > 0 && resolvedSettings.LivePhotoMovieDimensions.Height > 0) { capturingLivePhoto(true); } }
private void SetupCamera() { try { if (_captureSession == null) { _captureSession = new AVCaptureSession { SessionPreset = AVCaptureSession.PresetPhoto }; } SetPreviewSizing(); SetPreviewOrientation(); if (_photoOutput == null) { _device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video); TurnOffFlashAndSetContinuousAutoMode(_device); _photoOutput = new AVCapturePhotoOutput { IsHighResolutionCaptureEnabled = true }; _captureSession.AddOutput(_photoOutput); _captureSession.AddInput(AVCaptureDeviceInput.FromDevice(_device)); } } catch (Exception e) { _cameraModule.ErrorMessage = e.ToString(); } }
// ReSharper disable once UnusedMember.Local private void PhotoCaptureComplete(AVCapturePhotoOutput captureOutput, CMSampleBuffer finishedPhotoBuffer, CMSampleBuffer previewPhotoBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { try { if (error != null) { _cameraModule.ErrorMessage = error.ToString(); } else if (finishedPhotoBuffer != null) { LockPictureSpecificSettingsIfNothingCaptured(); using (var image = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(finishedPhotoBuffer, previewPhotoBuffer)) using (var imgDataProvider = new CGDataProvider(image)) using (var cgImage = CGImage.FromJPEG(imgDataProvider, null, false, CGColorRenderingIntent.Default)) using (var uiImage = UIImage.FromImage(cgImage, 1, GetOrientationForCorrection())) { _cameraModule.CapturedImage = uiImage.AsJPEG().ToArray(); } } } catch (Exception e) { _cameraModule.ErrorMessage = e.ToString(); } }
public virtual void WillBeginCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings) { if ((resolvedSettings.LivePhotoMovieDimensions.Width > 0) && (resolvedSettings.LivePhotoMovieDimensions.Height > 0)) { LivePhotoCaptureHandler(true); } }
// ReSharper disable once UnusedMember.Local private void PhotoJustGotCaptured(AVCapturePhotoOutput photoOutput, AVCaptureResolvedPhotoSettings settings) { if (_cameraModule.BluetoothOperator.IsPrimary || _cameraModule.BluetoothOperator.PairStatus != PairStatus.Connected) { _cameraModule.CaptureSuccess = !_cameraModule.CaptureSuccess; } }
public virtual void DidFinishProcessingLivePhotoMovie(AVCapturePhotoOutput captureOutput, NSUrl outputFileUrl, CMTime duration, CMTime photoDisplayTime, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error processing live photo companion movie: {error}", error); return; } }
public override void DidFinishCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (ShouldSaveCaptureResult(error)) { PHAssetManager.PerformChangesWithAuthorization(TryToAddPhotoToLibrary, null, DidFinish); } }
public override void DidFinishProcessingLivePhotoMovie(AVCapturePhotoOutput captureOutput, NSUrl outputFileUrl, CMTime duration, CMTime photoDisplayTime, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error processing live photo companion movie: {error.LocalizedDescription})"); return; } livePhotoCompanionMovieUrl = outputFileUrl; }
public void DidFinishProcessingLivePhotoMovie (AVCapturePhotoOutput captureOutput, NSUrl outputFileUrl, CMTime duration, CMTime photoDisplayTime, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine ($"Error processing live photo companion movie: {error.LocalizedDescription})"); return; } livePhotoCompanionMovieUrl = outputFileUrl; }
public virtual void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, AVCapturePhoto photo, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error}", error); return; } PhotoData = photo.FileDataRepresentation(); }
void SetupPhotoCapture() { captureSession.SessionPreset = AVCaptureSession.PresetPhoto; // Add photo output. photoOutput = new AVCapturePhotoOutput(); photoOutput.IsHighResolutionCaptureEnabled = true; captureSession.AddOutput(photoOutput); captureSession.CommitConfiguration(); }
public override void DidFinishCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error.LocalizedDescription})"); DidFinish(); return; } if (photoData == null) { Console.WriteLine("No photo data resource"); DidFinish(); return; } PHPhotoLibrary.RequestAuthorization(status => { if (status == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => { var options = new PHAssetResourceCreationOptions { UniformTypeIdentifier = RequestedPhotoSettings.ProcessedFileType, }; var creationRequest = PHAssetCreationRequest.CreationRequestForAsset(); creationRequest.AddResource(PHAssetResourceType.Photo, photoData, options); var url = livePhotoCompanionMovieUrl; if (url != null) { var livePhotoCompanionMovieFileResourceOptions = new PHAssetResourceCreationOptions { ShouldMoveFile = true }; creationRequest.AddResource(PHAssetResourceType.PairedVideo, url, livePhotoCompanionMovieFileResourceOptions); } }, (success, err) => { if (err != null) { Console.WriteLine($"Error occurered while saving photo to photo library: {error.LocalizedDescription}"); } DidFinish(); }); } else { DidFinish(); } }); }
public override void DidFinishProcessingPhoto(AVCapturePhotoOutput output, AVCapturePhoto photo, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error.LocalizedDescription}"); } else { photoData = photo.FileDataRepresentation; } }
public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer != null) { photoData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); } else { Console.WriteLine($"Error capturing photo: {error.LocalizedDescription}"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); OCR = new TesseractApi(); CaptureSession = new AVCaptureSession(); ImageOutput = new AVCapturePhotoOutput(); var cameraDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); var cameraInput = AVCaptureDeviceInput.FromDevice(cameraDevice); CaptureSession.AddInput(cameraInput); CaptureSession.AddOutput(ImageOutput); SetupUI(); CaptureSession.StartRunning(); Camera = new CameraHandler(); Camera.FinishedProcessing += async delegate { PictureView.Image = new UIImage(Camera.Picture, 1f, UIImageOrientation.Right); Capture = PictureView.Capture(); await InitReader(); }; OCRButton.TouchUpInside += async delegate { HandleButtonClick(); }; AlphaNumericSwitch.ValueChanged += async delegate { await SetOcrTextLabel(); }; // Selection slider Setup SelectionBarSlider.TouchUpInside += async delegate { await InitReader(); }; SelectionBarSlider.TouchUpOutside += async delegate { await InitReader(); }; SelectionBarSlider.ValueChanged += delegate { var tempFrame = SelectionBarView.Frame; tempFrame.Y = (SelectionBarSlider.Value * 92) + 22; SelectionBarView.Frame = tempFrame; }; }
public virtual void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, AVCapturePhoto photo, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error}", error); return; } PhotoData = photo.FileDataRepresentation(); DataManager.SheduleAddMachinePhotoRequest(Application.selectedMachine.ID, PhotoData.ToArray(), null); }
public virtual void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, AVCapturePhoto photo, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error}", error); return; } PhotoData = photo.FileDataRepresentation(); imageBytes = new byte[PhotoData.Length]; System.Runtime.InteropServices.Marshal.Copy(PhotoData.Bytes, imageBytes, 0, Convert.ToInt32(PhotoData.Length)); }
void SetupPhotoCapture() { captureSession.SessionPreset = AVCaptureSession.PresetPhoto; // Add photo output. photoOutput = new AVCapturePhotoOutput(); photoOutput.IsHighResolutionCaptureEnabled = true; if (captureSession.CanAddOutput(photoOutput)) { captureSession.AddOutput(photoOutput); } }
// キャプチャー後処理 public override void DidFinishCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error.LocalizedDescription})"); return; } if (photoData == null) { Console.WriteLine("No photo data resource"); return; } // 撮影したラベル画像をフォトアルバムに保存するか // フォトアルバムに保存する必要が出てきた真偽値をTrueにする bool IsSaveToPhotoAlbum = false; // 画像を保存するかどうかの判定 if (IsSaveToPhotoAlbum) { // 撮影した画像を保存する処理 PHPhotoLibrary.RequestAuthorization(status => { if (status == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => { var creationRequest = PHAssetCreationRequest.CreationRequestForAsset(); creationRequest.AddResource(PHAssetResourceType.Photo, photoData, null); var url = livePhotoCompanionMovieUrl; if (url != null) { var livePhotoCompanionMovieFileResourceOptions = new PHAssetResourceCreationOptions { ShouldMoveFile = true }; creationRequest.AddResource(PHAssetResourceType.PairedVideo, url, livePhotoCompanionMovieFileResourceOptions); } }, (success, err) => { if (err != null) { Console.WriteLine($"Error occurered while saving photo to photo library: {error.LocalizedDescription}"); } }); } }); } }
public void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { try { var jpegData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); var photo = UIImage.LoadFromData(jpegData); GoToDescription(photo, orientationOnPhoto); } catch (Exception ex) { AppSettings.Reporter.SendCrash(ex); ShowAlert(Core.Localization.LocalizationKeys.PhotoProcessingError); } }
public virtual void DidFinishCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error}", error); } if (PhotoData == null) { Console.WriteLine("No photo data resource"); } CompletionHandler(imageBytes); }
public virtual async void DidFinishCapture(AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine($"Error capturing photo: {error}", error); DidFinish(); return; } if (PhotoData == null) { Console.WriteLine("No photo data resource"); DidFinish(); return; } var status = await Photos.PHPhotoLibrary.RequestAuthorizationAsync(); if (status == Photos.PHAuthorizationStatus.Authorized) { Photos.PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => { var options = new Photos.PHAssetResourceCreationOptions(); options.UniformTypeIdentifier = RequestedPhotoSettings.ProcessedFileType(); var creationRequest = Photos.PHAssetCreationRequest.CreationRequestForAsset(); creationRequest.AddResource(Photos.PHAssetResourceType.Photo, PhotoData, options); if (LivePhotoCompanionMovieUrl != null) { var livePhotoCompanionMovieResourceOptions = new Photos.PHAssetResourceCreationOptions(); livePhotoCompanionMovieResourceOptions.ShouldMoveFile = true; creationRequest.AddResource(Photos.PHAssetResourceType.PairedVideo, LivePhotoCompanionMovieUrl, livePhotoCompanionMovieResourceOptions); } }, (success, completeError) => { if (!success) { Console.WriteLine($"Error occurred while saving photo to photo library: {error}"); } DidFinish(); }); } else { Console.WriteLine(@"Not authorized to save photo"); DidFinish(); } }
public void TestConstructor() { TestRuntime.AssertXcodeVersion(8, 0); AVCaptureAutoExposureBracketedStillImageSettings [] array = new AVCaptureAutoExposureBracketedStillImageSettings [3]; array [0] = AVCaptureAutoExposureBracketedStillImageSettings.Create(-2f); array [1] = AVCaptureAutoExposureBracketedStillImageSettings.Create(0f); array [2] = AVCaptureAutoExposureBracketedStillImageSettings.Create(2f); var output = new AVCapturePhotoOutput(); if (output.AvailablePhotoPixelFormatTypes.Length > 0) { using (var settings = AVCapturePhotoBracketSettings.FromRawPixelFormatType((uint)output.AvailablePhotoPixelFormatTypes [0], null, array)) Assert.That(settings.Handle, Is.Not.EqualTo(IntPtr.Zero)); } }
public void DidFinishCapture (AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings, NSError error) { if (error != null) { Console.WriteLine ($"Error capturing photo: {error.LocalizedDescription})"); DidFinish (); return; } if (photoData == null) { Console.WriteLine ("No photo data resource"); DidFinish (); return; } PHPhotoLibrary.RequestAuthorization (status => { if (status == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.PerformChanges (() => { var creationRequest = PHAssetCreationRequest.CreationRequestForAsset (); creationRequest.AddResource (PHAssetResourceType.Photo, photoData, null); var url = livePhotoCompanionMovieUrl; if (url != null) { var livePhotoCompanionMovieFileResourceOptions = new PHAssetResourceCreationOptions { ShouldMoveFile = true }; creationRequest.AddResource (PHAssetResourceType.PairedVideo, url, livePhotoCompanionMovieFileResourceOptions); } }, (success, err) => { if (err != null) Console.WriteLine ($"Error occurered while saving photo to photo library: {error.LocalizedDescription}"); DidFinish (); }); } else { DidFinish (); } }); }
public void DidFinishRecordingLivePhotoMovie (AVCapturePhotoOutput captureOutput, NSUrl outputFileUrl, AVCaptureResolvedPhotoSettings resolvedSettings) { capturingLivePhoto (false); }
void ConfigureSession () { if (setupResult != SetupResult.Success) return; NSError error = null; Session.BeginConfiguration (); Session.SessionPreset = AVCaptureSession.PresetPhoto; // Add video input AVCaptureDevice vDevice = GetDeviceFrom (AVMediaType.Video, AVCaptureDevicePosition.Back); AVCaptureDeviceInput vDeviceInput = AVCaptureDeviceInput.FromDevice (vDevice, out error); if (error != null) { Console.WriteLine ("Could not create video device input: {0}", error); setupResult = SetupResult.SessionConfigurationFailed; Session.CommitConfiguration (); return; } if (Session.CanAddInput (vDeviceInput)) { Session.AddInput (vDeviceInput); VideoDeviceInput = vDeviceInput; VideoDevice = vDeviceInput.Device; } else { Console.WriteLine ("Could not add video device input to the session"); setupResult = SetupResult.SessionConfigurationFailed; Session.CommitConfiguration (); return; } // Add audio input AVCaptureDevice aDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Audio); AVCaptureDeviceInput aDeviceInput = AVCaptureDeviceInput.FromDevice (aDevice, out error); if (error != null) Console.WriteLine ("Could not create audio device input: {0}", error); if (Session.CanAddInput (aDeviceInput)) Session.AddInput (aDeviceInput); else Console.WriteLine ("Could not add audio device input to the session"); // Add photo output var po = new AVCapturePhotoOutput (); if (Session.CanAddOutput (po)) { Session.AddOutput (po); photoOutput = po; photoOutput.IsHighResolutionCaptureEnabled = true; } else { Console.WriteLine ("Could not add photo output to the session"); setupResult = SetupResult.SessionConfigurationFailed; Session.CommitConfiguration (); return; } // We will not create an AVCaptureMovieFileOutput when configuring the session because the AVCaptureMovieFileOutput does not support movie recording with AVCaptureSessionPresetPhoto backgroundRecordingID = -1; Session.CommitConfiguration (); DispatchQueue.MainQueue.DispatchAsync (ConfigureManualHUD); }
void WillCapturePhoto (AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings) { DispatchQueue.MainQueue.DispatchAsync (() => { PreviewView.Layer.Opacity = 0; UIView.Animate (0.25, () => { PreviewView.Layer.Opacity = 1; }); }); }
void DidFinishProcessingPhoto (AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer == null) { Console.WriteLine ($"Error occurred while capturing photo: {error}"); return; } NSData imageData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation (photoSampleBuffer, previewPhotoSampleBuffer); PHPhotoLibrary.RequestAuthorization (status => { if (status == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.PerformChanges (() => { PHAssetCreationRequest.CreationRequestForAsset ().AddResource (PHAssetResourceType.Photo, imageData, null); }, (success, err) => { if (!success) { Console.WriteLine ($"Error occurred while saving photo to photo library: {err}"); } else { Console.WriteLine ("Photo was saved to photo library"); } }); } else { Console.WriteLine ("Not authorized to save photo"); } }); }
void DidFinishProcessingRawPhoto (AVCapturePhotoOutput captureOutput, CMSampleBuffer rawSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (rawSampleBuffer == null) { Console.WriteLine ($"Error occurred while capturing photo: {error}"); return; } var filePath = Path.Combine (Path.GetTempPath (), $"{resolvedSettings.UniqueID}.dng"); NSData imageData = AVCapturePhotoOutput.GetDngPhotoDataRepresentation (rawSampleBuffer, previewPhotoSampleBuffer); imageData.Save (filePath, true); PHPhotoLibrary.RequestAuthorization (status => { if (status == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.PerformChanges (() => { // In iOS 9 and later, it's possible to move the file into the photo library without duplicating the file data. // This avoids using double the disk space during save, which can make a difference on devices with limited free disk space. var options = new PHAssetResourceCreationOptions (); options.ShouldMoveFile = true; PHAssetCreationRequest.CreationRequestForAsset ().AddResource (PHAssetResourceType.Photo, filePath, options); // Add move (not copy) option }, (success, err) => { if (!success) Console.WriteLine ($"Error occurred while saving raw photo to photo library: {err}"); else Console.WriteLine ("Raw photo was saved to photo library"); NSError rErr; if (NSFileManager.DefaultManager.FileExists (filePath)) NSFileManager.DefaultManager.Remove (filePath, out rErr); }); } else { Console.WriteLine ("Not authorized to save photo"); } }); }
public void WillCapturePhoto (AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings) { willCapturePhotoAnimation (); }
public void WillBeginCapture (AVCapturePhotoOutput captureOutput, AVCaptureResolvedPhotoSettings resolvedSettings) { if (resolvedSettings.LivePhotoMovieDimensions.Width > 0 && resolvedSettings.LivePhotoMovieDimensions.Height > 0) capturingLivePhoto (true); }