Exemple #1
0
 public static void ToggleFlashlight()
 {
     try
     {
         var _myCamera = Methods.GetCamera(Configuration.CameraSource);
         if (_myCamera != null)
         {
             var prams = _myCamera.GetParameters();
             //prams.focus.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
             if (!IsTorchOn())
             {
                 prams.FlashMode = Android.Hardware.Camera.Parameters.FlashModeTorch;
             }
             else
             {
                 prams.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
             }
             _myCamera.SetParameters(prams);
         }
         else
         {
             Console.WriteLine($"Do not find camera");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error on switch on/off flashlight");
     }
 }
Exemple #2
0
        public void SetOrientation()
        {
            try
            {
                Android.Hardware.Camera camera = Methods.GetCamera(_cameraSource);
                switch (_windowManager.DefaultDisplay.Rotation)
                {
                case SurfaceOrientation.Rotation0:
                    camera?.SetDisplayOrientation(90);
                    break;

                case SurfaceOrientation.Rotation90:
                    camera?.SetDisplayOrientation(0);
                    break;

                case SurfaceOrientation.Rotation180:
                    camera?.SetDisplayOrientation(270);
                    break;

                case SurfaceOrientation.Rotation270:
                    camera?.SetDisplayOrientation(180);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error("BarcodeScanner.Droid", ex.Message);
            }
        }
Exemple #3
0
        public static bool IsTorchOn()
        {
            var  _myCamera = Methods.GetCamera(Configuration.CameraSource);
            bool torchOn   = false;

            if (_myCamera != null)
            {
                string flashModeStatus = _myCamera.GetParameters().FlashMode;
                torchOn = flashModeStatus == Android.Hardware.Camera.Parameters.FlashModeTorch;
            }
            return(torchOn);
        }
        public void SetOrientation()
        {
            Android.Hardware.Camera camera = Methods.GetCamera(_cameraSource);
            switch (_windowManager.DefaultDisplay.Rotation)
            {
            case SurfaceOrientation.Rotation0:
                camera?.SetDisplayOrientation(90);
                break;

            case SurfaceOrientation.Rotation90:
                camera?.SetDisplayOrientation(0);
                break;

            case SurfaceOrientation.Rotation180:
                camera?.SetDisplayOrientation(270);
                break;

            case SurfaceOrientation.Rotation270:
                camera?.SetDisplayOrientation(180);
                break;
            }
        }