public void TakePhoto() { if (_context == null || CameraDevice == null) { return; } if (_captureBuilder == null) { _captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture); } _captureBuilder.AddTarget(_imageReader.Surface); _captureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture); SetAutoFlash(_captureBuilder); var windowManager = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); int rotation = (int)windowManager.DefaultDisplay.Rotation; int orientation = GetOrientation(rotation); _captureBuilder.Set(CaptureRequest.JpegOrientation, orientation); _previewSession.StopRepeating(); _previewSession.AbortCaptures(); _previewSession.Capture(_captureBuilder.Build(), new CameraCaptureStillPictureSessionCallback { OnCaptureCompletedAction = session => { UnlockFocus(); } }, null); // Play shutter sound to alert user that image was captured var am = (AudioManager)_context.GetSystemService(Context.AudioService); if (am != null && am.RingerMode == RingerMode.Normal) { var cameraSound = new MediaActionSound(); cameraSound.Load(MediaActionSoundType.ShutterClick); cameraSound.Play(MediaActionSoundType.ShutterClick); } }
public void CaptureStillPicture() { try { if (null == cameraDevice) { return; } // This is the CaptureRequest.Builder that we use to take a picture. var 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); // Orientation int rotation = (int)WindowManager.DefaultDisplay.Rotation; int orientation = GetOrientation(rotation); stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, orientation); captureSession.StopRepeating(); captureSession.AbortCaptures(); captureSession.Capture(stillCaptureBuilder.Build(), cameraCaptureCallback, null); // Play shutter sound to alert user that image was captured var am = (AudioManager)GetSystemService(AudioService); if (am != null && am.RingerMode == RingerMode.Normal) { var cameraSound = new MediaActionSound(); cameraSound.Load(MediaActionSoundType.ShutterClick); cameraSound.Play(MediaActionSoundType.ShutterClick); } } catch (CameraAccessException e) { e.PrintStackTrace(); } }