public CameraCollectionViewCellDelegate(Func <CameraCollectionViewCell> getCameraCellFunc, CaptureSession captureSession, CaptureSettings captureSettings) { _getCameraCellFunc = getCameraCellFunc; _captureSession = captureSession; _captureSettings = captureSettings; }
// Capture a still picture. This method should be called when we get a response in // {@link #mCaptureCallback} from both {@link #lockFocus()}. public void CaptureStillPicture() { try { var activity = Activity; if (null == activity || null == CameraDevice) { return; } // This is the CaptureRequest.Builder that we use to take a picture. //if (_stillCaptureBuilder == null) //{ _stillCaptureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture); //} _stillCaptureBuilder.AddTarget(_imageReader.Surface); // Use the same AE and AF modes as the preview. _stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture); SetAutoFlash(_stillCaptureBuilder); CaptureSession.StopRepeating(); CaptureSession.Capture(_stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null); } catch (CameraAccessException ex) { #if DEBUG ex.PrintStackTrace(); #endif } }
public static CaptureSession Create(Func <CameraCollectionViewCell> getCameraCellFunc, ImagePickerControllerDelegate imagePickerDelegate, CameraMode mode) { var captureSessionDelegate = new CaptureSessionDelegate(getCameraCellFunc); CaptureSession session; switch (mode) { case CameraMode.Photo: case CameraMode.PhotoAndLivePhoto: session = new CaptureSession(captureSessionDelegate, new SessionPhotoCapturingDelegate(getCameraCellFunc, imagePickerDelegate)); break; case CameraMode.PhotoAndVideo: session = new CaptureSession(captureSessionDelegate, new CaptureSessionVideoRecordingDelegate(getCameraCellFunc)); break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } session.PresetConfiguration = mode.CaptureSessionPresetConfiguration(); return(session); }
public static CaptureSession Create(SelfView parent) { // create a device input and attach it to the session var captureDevice = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video).FirstOrDefault(d => d.Position == AVCaptureDevicePosition.Front); if (captureDevice == null) { return(null); } var input = AVCaptureDeviceInput.FromDevice(captureDevice); if (input == null) { return(null); } var output = new AVCaptureMetadataOutput(); var cs = new CaptureSession(parent, input, output); // This must be set after the output is added to the sesssion output.MetadataObjectTypes = AVMetadataObjectType.Face; return(cs); }
public void CaptureStillPicture() { try { if (Device == null) { return; } // This is the CaptureRequest.Builder that we use to take a picture. if (stillCaptureBuilder == null) { stillCaptureBuilder = Device.CreateCaptureRequest(CameraTemplate.StillCapture); } stillCaptureBuilder.AddTarget(mImageReader.Surface); // Use the same AE and AF modes as the preview. stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture); SetAutoFlash(stillCaptureBuilder); // Orientation var windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); int rotation = (int)windowManager.DefaultDisplay.Rotation; stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation)); CaptureSession.StopRepeating(); CaptureSession.Capture(stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
public void CloseCamera() { try { CameraOpenCloseLock.Acquire(); if (null != CaptureSession) { CaptureSession.Close(); CaptureSession = null; } if (null != Device) { Device.Close(); Device = null; } if (null != mImageReader) { mImageReader.Close(); mImageReader = null; } } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera closing.", e); } finally { CameraOpenCloseLock.Release(); } }
private void pageInstallerCaptureStart_Commit(object sender, WizardPageConfirmEventArgs e) { try { var captureSession = CaptureSession.Start(_feedBuilder); using (var handler = new DialogTaskHandler(this)) _installerCapture.RunInstaller(handler); _installerCapture.CaptureSession = captureSession; } #region Error handling catch (OperationCanceledException) { e.Cancel = true; } catch (Exception ex) when(ex is IOException or InvalidOperationException) { e.Cancel = true; Log.Warn(ex); Msg.Inform(this, ex.Message, MsgSeverity.Warn); } catch (UnauthorizedAccessException ex) { e.Cancel = true; Log.Error(ex); Msg.Inform(this, ex.Message, MsgSeverity.Error); } #endregion }
// Closes the current {@link CurrentCameraDevice}. private void CloseCamera() { try { CameraOpenCloseLock.Acquire(); if (null != CaptureSession) { CaptureSession.Close(); CaptureSession = null; } if (null != CurrentCameraDevice) { CurrentCameraDevice.Close(); CurrentCameraDevice = null; } } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera closing.", e); } finally { CameraOpenCloseLock.Release(); } }
/// <summary> /// Capture a still picture. This method should be called when we get a response in /// CaptureCallback from both LockFocus() /// </summary> public void CaptureStillPicture() { try { var activity = Activity; if (null == activity || null == CameraDevice) { return; } // This is the CaptureRequest.Builder that we use to take a picture. CaptureRequest.Builder captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture); captureBuilder.AddTarget(mImageReader.Surface); // Use the same AE and AF modes as the preview. captureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture); SetAutoFlash(captureBuilder); // Orientation int rotation = (int)activity.WindowManager.DefaultDisplay.Rotation; captureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation)); var captureCallback = new CameraCaptureSessionCaptureCallback2(this); CaptureSession.StopRepeating(); CaptureSession.Capture(captureBuilder.Build(), captureCallback, null); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
void applicationWillEnterForeground() { sessionQueue.DispatchSync(delegate { if (running) { CaptureSession.StartRunning(); } }); }
protected override void Dispose(bool disposing) { if (disposing && captureSession != null) { captureSession.Dispose(); captureSession = null; } base.Dispose(disposing); }
// Closes the current {@link CameraDevice}. protected void CloseCamera() { if (CaptureSession == null) { return; } try { CameraOpenCloseLock.Acquire(); if (null != CaptureSession) { try { CaptureSession.StopRepeating(); CaptureSession.AbortCaptures(); } catch (CameraAccessException ex) { #if DEBUG ex.PrintStackTrace(); #endif } catch (IllegalStateException ex) { #if DEBUG ex.PrintStackTrace(); #endif } CaptureSession.Close(); CaptureSession = null; } if (null != CameraDevice) { CameraDevice.Close(); CameraDevice = null; } if (null != _imageReader) { _imageReader.Close(); _imageReader = null; } } catch (InterruptedException ex) { throw new RuntimeException("Interrupted while trying to lock camera closing.", ex); } finally { CameraOpenCloseLock.Release(); } }
public void StopPreviewing() { if (!IsPreviewing) { return; } CaptureSession.StopRunning(); IsPreviewing = false; previewLayer.Hidden = true; }
public void StartPreviewing() { if (IsPreviewing) { return; } CaptureSession.StartRunning(); IsPreviewing = true; previewLayer.Hidden = false; }
public void StopRunning() { sessionQueue.DispatchSync(delegate { running = false; CaptureSession.StopRunning(); captureSessionStoppedRunning(); teardownCaptureSession(); }); }
public void Release() { CaptureSession.StopRunning(); Recorder.Dispose(); Queue.Dispose(); CaptureSession.RemoveOutput(Output); CaptureSession.RemoveInput(Input); Output.Dispose(); Input.Dispose(); MainDevice.Dispose(); this.RemoveGestureRecognizer(Pinch); }
public void StartRunning() { sessionQueue.DispatchSync(delegate { try { setupCaptureSession(); CaptureSession.StartRunning(); running = true; metadataOutput.MetadataObjectTypes = AVMetadataObjectType.QRCode; } catch (Exception e) { Console.WriteLine(e.Message); } }); }
private void ConfigureCaptureSession() { if (!LayoutConfiguration.ShowsCameraItem) { return; } _captureSession = CaptureFactory.Create(GetCameraCell, Delegate, CaptureSettings.CameraMode); _captureSession.Prepare( GetCaptureVideoOrientation(UIApplication.SharedApplication.StatusBarOrientation)); _cameraCollectionViewCellDelegate = new CameraCollectionViewCellDelegate(GetCameraCell, _captureSession, CaptureSettings); }
public MeterValues(CaptureSession captureSession, AppSettings.Capture.Device source) { _captureSession = captureSession; RequestedScale = source.Scale?.StartsWith("Lin", StringComparison.OrdinalIgnoreCase) == true ? Scale.Linear : Scale.Logarithmic; Alias = Match(captureSession?.DeviceName, source.Label) ?? source.Label ?? string.Empty; ShowLevels = source.Levels; Id = captureSession.DeviceId; }
/// <summary> /// Create and run a capture session /// </summary> /// <returns></returns> private async Task RunCapture() { var captureSession = new CaptureSession(session.SettingsManager, Preferences); captureSession.AddAllSolutions(); await captureSession.Run(); hasCompletedCapture = true; if (session.User != null) { await session.Service.Save(Preferences); } CompleteIfAllDone(); }
void Initialize() { captureSession = CaptureSession.Create(this); if (captureSession == null) { //FIXME: This means the device doesn't have a camera.. BackgroundColor = UIColor.Gray; return; } Layer.MasksToBounds = true; captureSession.SetPreviewLayer(Layer); Layer.Connection.VideoOrientation = AVCaptureVideoOrientation.Portrait; Layer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill; }
public void LockFocus() { try { // This is how to tell the camera to lock focus. PreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start); // Tell #mCaptureCallback to wait for the lock. State = CameraState.WaitingLock; CaptureSession.Capture(PreviewRequestBuilder.Build(), CaptureCallback, BackgroundHandler); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
public void RunPrecaptureSequence() { try { // This is how to tell the camera to trigger. PreviewRequestBuilder.Set(CaptureRequest.ControlAePrecaptureTrigger, (int)ControlAEPrecaptureTrigger.Start); // Tell #mCaptureCallback to wait for the precapture sequence to be set. State = CameraState.WaitingPrecapture; CaptureSession.Capture(PreviewRequestBuilder.Build(), CaptureCallback, BackgroundHandler); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
/// <summary> /// Lock the focus as the first step for a still image capture. /// </summary> private void LockFocus() { try { // This is how to tell the camera to lock focus. PreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start); // Tell #CaptureCallback to wait for the lock. CurrentCameraState = STATE_WAITING_LOCK; // this will kick off the image-capture pipeline CaptureSession.Capture(PreviewRequestBuilder.Build(), CaptureCallback, BackgroundHandler); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
public void UnlockFocus() { try { // Reset the auto-focus trigger PreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Cancel); SetAutoFlash(PreviewRequestBuilder); CaptureSession.Capture(PreviewRequestBuilder.Build(), CaptureCallback, BackgroundHandler); // After this, the camera will go back to the normal state of preview. State = CameraState.Preview; CaptureSession.SetRepeatingRequest(PreviewRequest, CaptureCallback, BackgroundHandler); } catch (CameraAccessException e) { e.PrintStackTrace(); } }
public override void RemoveFromSuperview() { base.RemoveFromSuperview(); //Off the torch when exit page if (GoogleVisionBarCodeScanner.Methods.IsTorchOn()) { GoogleVisionBarCodeScanner.Methods.ToggleFlashlight(); } //Stop the capture session if not null try { if (CaptureSession != null) { CaptureSession.StopRunning(); } } catch { } }
private ExitCode Start() { if (_additionalArgs.Count != 2) { return(PrintHelp()); } string snapshotFile = _additionalArgs[1]; if (FileExists(snapshotFile)) { return(ExitCode.IOError); } var session = CaptureSession.Start(new FeedBuilder()); session.Save(snapshotFile); return(ExitCode.OK); }
public void UpdateCameraOption(CameraOptions option) { if (CameraOption == option) { return; } CameraOption = option; var cameraPosition = (CameraOption == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; var device = GetCameraForOrientation(cameraPosition); ConfigureCameraForDevice(device); CaptureSession.BeginConfiguration(); CaptureSession.RemoveInput(captureDeviceInput); captureDeviceInput = AVCaptureDeviceInput.FromDevice(device); CaptureSession.AddInput(captureDeviceInput); CaptureSession.CommitConfiguration(); }
private ExitCode Finish() { if (_additionalArgs.Count != 3) { return(PrintHelp()); } string snapshotFile = _additionalArgs[1]; string feedFile = _additionalArgs[2]; if (FileExists(feedFile)) { return(ExitCode.IOError); } var feedBuilder = new FeedBuilder(); var session = CaptureSession.Load(snapshotFile, feedBuilder); session.InstallationDir = _installationDirectory; session.Diff(_handler); feedBuilder.MainCandidate = string.IsNullOrEmpty(_mainExe) ? feedBuilder.Candidates.FirstOrDefault() : feedBuilder.Candidates.FirstOrDefault(x => StringUtils.EqualsIgnoreCase(FileUtils.UnifySlashes(x.RelativePath), _mainExe)); session.Finish(); if (!string.IsNullOrEmpty(_zipFile)) { if (FileExists(_zipFile)) { return(ExitCode.IOError); } var relativeUri = new Uri(Path.GetFullPath(feedFile)).MakeRelativeUri(new Uri(Path.GetFullPath(_zipFile))); session.CollectFiles(_zipFile, relativeUri, _handler); Log.Warn("If you wish to upload this feed and ZIP archive, make sure to turn the <archive>'s relative href into an absolute one."); } feedBuilder.Build().Save(feedFile); return(ExitCode.OK); }
public async Task Signin(User user, Preferences?preferences = null) { if (User == null) { // If we are going from no user to a logged in user, capture the computer's current settings as the // default preferences that will be applied back when the user logs out. // // If we are going from one user to another user, we don't want to do anything because the computer's // current settings are the first user's rather than whatever the computer was before that user logged in if (Preferences is Preferences defaultPreferences) { if (defaultPreferences.Id == "__default__") { var capture = new CaptureSession(SettingsManager, defaultPreferences); capture.AddAllSolutions(); await capture.Run(); await Storage.Save(defaultPreferences); } else { logger.LogError("User is null, but Preferences.Id != '__default__'; not capturing default settings on signin"); } } } User = user; if (preferences == null) { Preferences = null; preferences = await Service.FetchPreferences(user); } Preferences = preferences; await Storage.Save(user); if (Preferences != null) { await Storage.Save(Preferences); } UserChanged?.Invoke(this, new EventArgs()); }