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}"); }
partial void BtnShutter_TouchUpInside(UIButton sender) { var Settings = new AVCaptureBracketedStillImageSettings[] { AVCaptureAutoExposureBracketedStillImageSettings.Create(0f) }; // Tell the camera that we are getting ready to do a bracketed capture ThisApp.StillImageOutput.PrepareToCaptureStillImageBracket(ThisApp.StillImageOutput.Connections[0], Settings, (ready, err) => { // Was there an error, if so report it if (err != null) { Console.WriteLine("Error: {0}", err.LocalizedDescription); } }); // Ask the camera to snap a bracketed capture ThisApp.StillImageOutput.CaptureStillImageBracket(ThisApp.StillImageOutput.Connections[0], Settings, (sampleBuffer, settings, err) => { // Convert raw image stream into a Core Image Image var imageData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer); var image = CIImage.FromData(imageData); // Display the resulting image imageArray.Add(UIImage.FromImage(image)); btnCheck.Hidden = false; lblCount.Hidden = false; lblCount.Text = imageArray.Count.ToString(); }); }
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); } }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); // Hide no camera label NoCamera.Hidden = ThisApp.CameraAvailable; // Attach to camera view ThisApp.Recorder.DisplayView = CameraView; // Setup scrolling area ScrollView.ContentSize = new CGSize(CameraView.Frame.Width * 4, CameraView.Frame.Height); // Add output views Output.Add(BuildOutputView(1)); Output.Add(BuildOutputView(2)); Output.Add(BuildOutputView(3)); // Create preset settings var Settings = new AVCaptureBracketedStillImageSettings[] { AVCaptureAutoExposureBracketedStillImageSettings.Create(-2.0f), AVCaptureAutoExposureBracketedStillImageSettings.Create(0.0f), AVCaptureAutoExposureBracketedStillImageSettings.Create(2.0f) }; // Wireup capture button CaptureButton.TouchUpInside += (sender, e) => { // Reset output index OutputIndex = 0; // Tell the camera that we are getting ready to do a bracketed capture ThisApp.StillImageOutput.PrepareToCaptureStillImageBracket(ThisApp.StillImageOutput.Connections[0], Settings, (bool ready, NSError err) => { // Was there an error, if so report it if (err != null) { Console.WriteLine("Error: {0}", err.LocalizedDescription); } }); // Ask the camera to snap a bracketed capture ThisApp.StillImageOutput.CaptureStillImageBracket(ThisApp.StillImageOutput.Connections[0], Settings, (sampleBuffer, settings, err) => { // Convert raw image stream into a Core Image Image var imageData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer); var image = CIImage.FromData(imageData); // Display the resulting image Output[OutputIndex++].Image = UIImage.FromImage(image); // IMPORTANT: You must release the buffer because AVFoundation has a fixed number // of buffers and will stop delivering frames if it runs out. sampleBuffer.Dispose(); }); }; }
public override void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer != null) { PhotoData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); } else if (error != null) { Console.WriteLine($"photo capture delegate: error capturing photo: {error}"); ProcessError = error; } }
public override void DidFinishProcessingPhoto(AVCapturePhotoOutput captureOutput, CMSampleBuffer photoSampleBuffer, CMSampleBuffer previewPhotoSampleBuffer, AVCaptureResolvedPhotoSettings resolvedSettings, AVCaptureBracketedStillImageSettings bracketSettings, NSError error) { if (photoSampleBuffer != null) { _photoData = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(photoSampleBuffer, previewPhotoSampleBuffer); } else { System.Diagnostics.Debug.WriteLine(string.Format("Error capturing photo: {0}", error.LocalizedDescription)); } PictureTaken?.Invoke(this, _photoData); }
public void DidFinishProcessingPhoto( AVCapturePhotoOutput output, CMSampleBuffer buffer1, CMSampleBuffer buffer2, AVCaptureResolvedPhotoSettings resolvedPhotoSettings, AVCaptureBracketedStillImageSettings bracketedStillImageSettings, NSError error ) { if (_photoCapturePath == null) { throw new ArgumentNullException(_photoCapturePath); } var data = AVCapturePhotoOutput.GetJpegPhotoDataRepresentation(buffer1, buffer2); var bytes = data.ToArray(); File.WriteAllBytes(_photoCapturePath, bytes); _photoCapturePath = null; }
// Should be called on the main queue AVCapturePhotoSettings GetCurrentPhotoSettings () { bool lensStabilizationEnabled = LensStabilizationControl.SelectedSegment == 1; bool rawEnabled = RawControl.SelectedSegment == 1; AVCapturePhotoSettings photoSettings = null; if (lensStabilizationEnabled && photoOutput.IsLensStabilizationDuringBracketedCaptureSupported) { AVCaptureBracketedStillImageSettings [] bracketedSettings = null; if (VideoDevice.ExposureMode == AVCaptureExposureMode.Custom) { bracketedSettings = new AVCaptureBracketedStillImageSettings [] { AVCaptureManualExposureBracketedStillImageSettings.Create(AVCaptureDevice.ExposureDurationCurrent, AVCaptureDevice.ISOCurrent) }; } else { bracketedSettings = new AVCaptureBracketedStillImageSettings []{ AVCaptureAutoExposureBracketedStillImageSettings.Create(AVCaptureDevice.ExposureTargetBiasCurrent) }; } if (rawEnabled && photoOutput.AvailableRawPhotoPixelFormatTypes.Length > 0) { photoSettings = AVCapturePhotoBracketSettings.FromRawPixelFormatType (photoOutput.AvailableRawPhotoPixelFormatTypes [0].UInt32Value, null, bracketedSettings); } else { // TODO: https://bugzilla.xamarin.com/show_bug.cgi?id=44111 photoSettings = AVCapturePhotoBracketSettings.FromRawPixelFormatType (0, new NSDictionary<NSString, NSObject> (AVVideo.CodecKey, new NSNumber ((int)AVVideoCodec.JPEG)), bracketedSettings); } ((AVCapturePhotoBracketSettings)photoSettings).IsLensStabilizationEnabled = true; } else { if (rawEnabled && photoOutput.AvailableRawPhotoPixelFormatTypes.Length > 0) { photoSettings = AVCapturePhotoSettings.FromRawPixelFormatType (photoOutput.AvailableRawPhotoPixelFormatTypes [0].UInt32Value); } else { photoSettings = AVCapturePhotoSettings.Create (); } // We choose not to use flash when doing manual exposure if (VideoDevice.ExposureMode == AVCaptureExposureMode.Custom) { photoSettings.FlashMode = AVCaptureFlashMode.Off; } else { photoSettings.FlashMode = photoOutput.SupportedFlashModes.Contains (new NSNumber ((long)AVCaptureFlashMode.Auto)) ? AVCaptureFlashMode.Auto : AVCaptureFlashMode.Off; } } // 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]); if (VideoDevice.ExposureMode == AVCaptureExposureMode.Custom) photoSettings.IsAutoStillImageStabilizationEnabled = false; photoSettings.IsHighResolutionPhotoEnabled = true; return photoSettings; }
// 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(); } }
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"); } }); }
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); var inSampleSize = ImageHelper.CalculateInSampleSize(photo.Size, Core.Constants.PhotoMaxSize, Core.Constants.PhotoMaxSize); var deviceRatio = Math.Round(UIScreen.MainScreen.Bounds.Width / UIScreen.MainScreen.Bounds.Height, 2); var x = ((float)inSampleSize.Width - Core.Constants.PhotoMaxSize * (float)deviceRatio) / 2f; photo = ImageHelper.CropImage(photo, x, 0, Core.Constants.PhotoMaxSize * (float)deviceRatio, Core.Constants.PhotoMaxSize, inSampleSize); GoToDescription(photo, orientationOnPhoto); } catch (Exception ex) { AppSettings.Reporter.SendCrash(ex); ShowAlert(Core.Localization.LocalizationKeys.PhotoProcessingError); } }
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"); } }); }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad () { base.ViewDidLoad (); // Hide no camera label NoCamera.Hidden = ThisApp.CameraAvailable; // Attach to camera view ThisApp.Recorder.DisplayView = CameraView; // Setup scrolling area ScrollView.ContentSize = new CGSize (CameraView.Frame.Width * 4f, CameraView.Frame.Height); // Add output views Output.Add (BuildOutputView (1)); Output.Add (BuildOutputView (2)); Output.Add (BuildOutputView (3)); // Create preset settings var Settings = new AVCaptureBracketedStillImageSettings[] { AVCaptureAutoExposureBracketedStillImageSettings.Create (-2f), AVCaptureAutoExposureBracketedStillImageSettings.Create (0f), AVCaptureAutoExposureBracketedStillImageSettings.Create (2f) }; OutputIndex = Settings.Length; // Wireup capture button CaptureButton.TouchUpInside += (sender, e) => { // Reset output index if (OutputIndex < Settings.Length) return; OutputIndex = 0; // Tell the camera that we are getting ready to do a bracketed capture ThisApp.StillImageOutput.PrepareToCaptureStillImageBracket (ThisApp.StillImageOutput.Connections [0], Settings, (ready, err) => { // Was there an error, if so report it if (err != null) Console.WriteLine ("Error: {0}", err.LocalizedDescription); }); // Ask the camera to snap a bracketed capture ThisApp.StillImageOutput.CaptureStillImageBracket (ThisApp.StillImageOutput.Connections [0], Settings, (sampleBuffer, settings, err) => { // Convert raw image stream into a Core Image Image var imageData = AVCaptureStillImageOutput.JpegStillToNSData (sampleBuffer); var image = CIImage.FromData (imageData); // Display the resulting image Output [OutputIndex++].Image = UIImage.FromImage (image); // IMPORTANT: You must release the buffer because AVFoundation has a fixed number // of buffers and will stop delivering frames if it runs out. sampleBuffer.Dispose (); }); }; }
// 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) { if (!(_cameraModule.BluetoothOperator.PairStatus == PairStatus.Connected && !_cameraModule.BluetoothOperator.IsPrimary)) { LockPictureSpecificSettingsIfApplicable(); } 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())) { var imageBytes = uiImage.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(); } }
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 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}"); } }
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); } }
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 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 { 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); } }