/** * Starts or restarts the camera source, if it exists. If the camera source doesn't exist yet * (e.g., because onResume was called before the camera source was created), this will be called * again when the camera source is created. */ private void StartCameraSource() { try { CameraSourcePreview.Start(MCameraSource, MGraphicOverlay); } catch (Exception e) { Android.Util.Log.Error(TAG, "Unable to start camera source.", e); MCameraSource.Release(); MGraphicOverlay = null; // Crashlytics.Crashlytics.LogException(Java.Lang.Throwable.FromException(e)); } }
private void TorchFab_Click(object sender, EventArgs e) { if (CoreCamera == null) { var javaCam = MCameraSource.JavaCast <Java.Lang.Object>(); var fields = javaCam.Class.GetDeclaredFields(); foreach (Field field in fields) { if (!field.Type.CanonicalName.Equals("android.hardware.camera", StringComparison.OrdinalIgnoreCase)) { continue; } field.Accessible = true; Object camera = field.Get(javaCam); CoreCamera = (Camera)camera; } } if (!IsFlashOn) { if (CoreCamera != null) { Camera.Parameters prams = CoreCamera.GetParameters(); prams.FlashMode = Camera.Parameters.FlashModeTorch; CoreCamera.SetParameters(prams); } IsFlashOn = true; } else { Camera.Parameters prams = CoreCamera.GetParameters(); prams.FlashMode = Camera.Parameters.FlashModeOff; CoreCamera.SetParameters(prams); IsFlashOn = false; } }