void BttFlash_TouchUpInside(object sender, EventArgs e) { var device = captureDeviceInput.Device; var error = new NSError(); if (device.HasFlash) { if (device.FlashMode == AVCaptureFlashMode.On) { device.LockForConfiguration(out error); device.FlashMode = AVCaptureFlashMode.Off; device.UnlockForConfiguration(); ButtonFlash.SetImage(UIImage.FromBundle("flash_off").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); } else { device.LockForConfiguration(out error); device.FlashMode = AVCaptureFlashMode.On; device.UnlockForConfiguration(); ButtonFlash.SetImage(UIImage.FromBundle("flash_on").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); } } }
public void SetupLiveCameraStream() { captureSession = new AVCaptureSession(); var viewLayer = CameraView.Layer; videoPreviewLayer = new AVCaptureVideoPreviewLayer(captureSession) { Frame = this.View.Bounds }; videoPreviewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill; CameraView.Layer.AddSublayer(videoPreviewLayer); var captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); ConfigureCameraForDevice(captureDevice); captureDeviceInput = AVCaptureDeviceInput.FromDevice(captureDevice); captureSession.AddInput(captureDeviceInput); var dictionary = new NSMutableDictionary(); dictionary[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG); stillImageOutput = new AVCaptureStillImageOutput() { OutputSettings = new NSDictionary() }; captureSession.AddOutput(stillImageOutput); captureSession.StartRunning(); ButtonBack.SetImage(UIImage.FromBundle("arrow_left").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); ButtonFlash.SetImage(UIImage.FromBundle("flash_off").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); ButtonSwitch.SetImage(UIImage.FromBundle("switch_camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); ButtonCapture.SetImage(UIImage.FromBundle("capture_camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); ButtonFlash.TouchUpInside += BttFlash_TouchUpInside; ButtonCapture.TouchUpInside += BttCapture_TouchUpInside; ButtonBack.TouchUpInside += BttBack_TouchUpInside; ButtonSwitch.TouchUpInside += BttSwitch_TouchUpInside; }