/// <summary> /// Create flash configuration /// </summary> /// <param name="torch"><see cref="bool"/></param> protected void FlashConfiguration(bool torch) { try { if (Device == null) { return; } NSError error; if (Device.LockForConfiguration(out error)) { if (!torch && Device.HasFlash) { Device.FlashMode = AVCaptureFlashMode.Off; FlashButton.SetImage(FlashOffImage, UIControlState.Normal); } else if (torch && Device.HasTorch) { Device.TorchMode = AVCaptureTorchMode.Off; FlashButton.SetImage(FlashOffImage, UIControlState.Normal); } Device.UnlockForConfiguration(); } } catch { /* ignore */ } }
/// <summary> /// Set up images for buttons and set up gesture recognizers /// </summary> protected void Initialize() { if (Session != null) { return; } FlashOnImage = Configuration.FlashOnImage ?? UIImage.FromBundle("ic_flash_on"); FlashOffImage = Configuration.FlashOffImage ?? UIImage.FromBundle("ic_flash_off"); var flipImage = Configuration.FlipImage ?? UIImage.FromBundle("ic_loop"); if (Configuration.TintIcons) { FlashButton.TintColor = Configuration.TintColor; FlipButton.TintColor = Configuration.TintColor; FlashOnImage = FlashOnImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); FlashOffImage = FlashOffImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); flipImage = flipImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); } FlashButton.SetImage(FlashOffImage, UIControlState.Normal); FlipButton.SetImage(flipImage, UIControlState.Normal); FocusView = new UIView(new CGRect(0, 0, 90, 90)); var tapRecognizer = new UITapGestureRecognizer(Focus); PreviewContainer.AddGestureRecognizer(tapRecognizer); Hidden = false; }
void ReleaseDesignerOutlets() { if (CamView != null) { CamView.Dispose(); CamView = null; } if (FlashButton != null) { FlashButton.Dispose(); FlashButton = null; } if (FlashImageView != null) { FlashImageView.Dispose(); FlashImageView = null; } if (Label != null) { Label.Dispose(); Label = null; } if (LabelForDocArea != null) { LabelForDocArea.Dispose(); LabelForDocArea = null; } if (LabelForDocDistortion != null) { LabelForDocDistortion.Dispose(); LabelForDocDistortion = null; } if (OverlayView != null) { OverlayView.Dispose(); OverlayView = null; } if (ProgressView != null) { ProgressView.Dispose(); ProgressView = null; } }
/// <summary> /// Toggle the flash or torch /// </summary> /// <param name="torch"><see cref="bool"/> indicating whether to use torch for video</param> protected void Flash(bool torch) { if (!CameraAvailable) { return; } try { NSError error; if (Device.LockForConfiguration(out error)) { if (torch && Device.HasTorch) { var mode = Device.TorchMode; if (mode == AVCaptureTorchMode.Off) { Device.TorchMode = AVCaptureTorchMode.On; FlashButton.SetImage(FlashOnImage, UIControlState.Normal); } else { Device.TorchMode = AVCaptureTorchMode.Off; FlashButton.SetImage(FlashOffImage, UIControlState.Normal); } } else if (!torch && Device.HasFlash) { var mode = Device.FlashMode; if (mode == AVCaptureFlashMode.Off) { Device.FlashMode = AVCaptureFlashMode.On; FlashButton.SetImage(FlashOnImage, UIControlState.Normal); } else { Device.FlashMode = AVCaptureFlashMode.Off; FlashButton.SetImage(FlashOffImage, UIControlState.Normal); } } Device.UnlockForConfiguration(); } } catch { FlashButton.SetImage(FlashOffImage, UIControlState.Normal); } }