Example #1
0
 public void SurfaceDestroyed(ISurfaceHolder holder)
 {
     if (isCameraInUse())
     {
         camera.StopPreview();
         camera.Release();
         camera = null;
     }
 }
Example #2
0
 public void StopRecord()
 {
     if (recorder != null)
     {
         recorder.Stop();
         recorder.Release();
         camera.StopPreview();
         camera.Release();
     }
 }
Example #3
0
        public override void OnPause()
        {
            base.OnPause();

            // Because the Camera object is a shared resource, it's very
            // important to release it when the activity is paused.
            if (mCamera != null)
            {
                mPreview.SetCamera(null);
                mCamera.Release();
                mCamera = null;
            }
        }
Example #4
0
        public bool OnSurfaceTextureDestroyed(Android.Graphics.SurfaceTexture surface)
        {
            camera.StopPreview();
            camera.Release();

            return(true);
        }
Example #5
0
        static Task ToggleTorchAsync(bool switchOn)
        {
            return(Task.Run(() =>
            {
                lock (locker)
                {
                    if (Platform.HasApiLevel(BuildVersionCodes.M) && !AlwaysUseCameraApi)
                    {
                        var cameraManager = Platform.CameraManager;
                        foreach (var id in cameraManager.GetCameraIdList())
                        {
                            var hasFlash = cameraManager.GetCameraCharacteristics(id).Get(CameraCharacteristics.FlashInfoAvailable);
                            if (Java.Lang.Boolean.True.Equals(hasFlash))
                            {
                                cameraManager.SetTorchMode(id, switchOn);
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (camera == null)
                        {
                            if (surface == null)
                            {
                                surface = new SurfaceTexture(0);
                            }

#pragma warning disable CS0618 // Camera types are deprecated in Android 10+
                            camera = Camera.Open();

                            // Nexus 5 and some devices require a preview texture
                            camera.SetPreviewTexture(surface);
                        }

                        var param = camera.GetParameters();

                        // Deprecated in an earlier android version
                        param.FlashMode = switchOn ? Camera.Parameters.FlashModeTorch : Camera.Parameters.FlashModeOff;

                        camera.SetParameters(param);

                        if (switchOn)
                        {
                            camera.StartPreview();
                        }
                        else
                        {
                            camera.StopPreview();
                            camera.Release();
                            camera.Dispose();
#pragma warning restore CS0618 // Type or member is obsolete
                            camera = null;
                            surface.Dispose();
                            surface = null;
                        }
                    }
                }
            }));
        }
Example #6
0
 private void StopCamera()
 {
     camera.SetPreviewCallback(null);
     camera.StopPreview();
     camera.Release();
     camera = null;
 }
Example #7
0
 public void StopCamera()
 {
     if (mCamera != null)
     {
         try
         {
             mCamera.StopPreview();
             mCamera.SetPreviewDisplay(null);
             mCamera.SetPreviewCallback(null);
             mCamera.Lock();
             mCamera.Release();
             mCamera = null;
             hldr.RemoveCallback(this);
             if (ForegroundService.windowManager != null)
             {
                 if (ForegroundService._globalSurface != null)
                 {
                     ForegroundService.windowManager.RemoveView(ForegroundService._globalSurface);
                     ForegroundService.windowManager  = null;
                     ForegroundService._globalSurface = null;
                 }
             }
             ForegroundService._globalService.CamInService();
             try { ((MainActivity)MainActivity.global_activity).soketimizeGonder("CAMREADY", "[VERI][0x09]"); } catch (Exception) { }
         }
         catch (Exception) { }
     }
 }
Example #8
0
        public bool OnSurfaceTextureDestroyed(SurfaceTexture surface)
        {
            _camera.StopPreview();
            _camera.Release();

            return(true);
        }
Example #9
0
 public void StopCamera()
 {
     if (mCamera != null)
     {
         try
         {
             mCamera.StopPreview();
             mCamera.SetPreviewDisplay(null);
             mCamera.SetPreviewCallback(null);
             mCamera.Lock();
             mCamera.Release();
             mCamera = null;
             hldr.RemoveCallback(this);
             if (ForegroundService.windowManager != null)
             {
                 if (ForegroundService._globalSurface != null)
                 {
                     ForegroundService.windowManager.RemoveView(ForegroundService._globalSurface);
                     ForegroundService._globalSurface.Dispose();
                 }
                 ForegroundService.windowManager.Dispose();
             }
             ForegroundService._globalService.CamInService();
         }
         catch (Exception) { }
     }
     if (camSock != null)
     {
         try { camSock.Close(); } catch { }
         try { camSock.Dispose(); } catch { }
     }
 }
Example #10
0
        public bool OnSurfaceTextureDestroyed(Android.Graphics.SurfaceTexture surface)
        {
            Toast.MakeText(this, "About to break texture", ToastLength.Short).Show();
            _camera.StopPreview();
            _camera.Release();

            return(true);
        }
Example #11
0
        protected override void OnPause()
        {
            m_LocationManager.RemoveUpdates(this);

            m_Camera.StopPreview();
            m_Camera.Release();
            base.OnPause();
        }
        private void StopCamera()
        {
            _camera.StopPreview();
            _camera.Release();
            GC.Collect();
            var mem = GC.GetTotalMemory(true);

            System.Diagnostics.Debug.WriteLine($"Memory: { mem }");
        }
Example #13
0
        public void SurfaceDestroyed(ISurfaceHolder holder)
        {
            Logger.LogInfo(nameof(SurfaceHolderCallback), nameof(SurfaceDestroyed), "called.");

            _Camera.StopPreview();
            _Camera.Release();
            _Camera.Dispose();
            _Camera = null;
        }
 private void StopCamera()
 {
     if ((Element as VideoCameraPage).IsPreviewing)
     {
         camera.StopPreview();
         camera.Release();
         (Element as VideoCameraPage).IsPreviewing = false;
     }
 }
Example #15
0
 private void StopCamera()
 {
     if (_camera != null)
     {
         _camera.StopPreview();
         _camera.Release();
         _camera = null;
     }
 }
Example #16
0
 public void SurfaceDestroyed(ISurfaceHolder holder)
 {
     // Surface will be destroyed when we return, so stop the preview.
     // Because the CameraDevice object is not a shared resource, it's very
     // important to release it when the activity is paused.
     camera.StopPreview();
     camera.Release();
     camera = null;
 }
Example #17
0
 public void SurfaceDestroyed(ISurfaceHolder holder)
 {
     // throw new NotImplementedException();
     holder.RemoveCallback(this);
     camera.SetPreviewCallback(null);
     camera.StopPreview();
     camera.Release();
     camera = null;
 }
Example #18
0
 public void OnPictureTaken(byte[] data, Camera camera)
 {
     if (data != null)
     {
         Photo = data;
         _camera.Unlock();
         _camera.StopPreview();
         _camera.Release();
     }
 }
Example #19
0
        protected override void OnDestroy()
        {
            camera.StopPreview();
            camera.Release();
            cameraReleased = true;

            root.Click           -= AutofocusCalled;
            caprtureButton.Click -= CaptureClicked;
            base.OnDestroy();
        }
Example #20
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e)
        {
            base.OnElementChanged(e);
            if (camera != null)
            {
                camera.Release();
                camera = null;
            }
            camera = Android.Hardware.Camera.Open();
            camera.SetDisplayOrientation(90);
            Parameters parameters = camera.GetParameters();

            parameters.FocusMode = Parameters.FocusModeContinuousVideo;
            camera.SetParameters(parameters);

            SetupUserInterface();
            SetupEventHandlers();
            AddView(view);
        }
 private void CameraClose(bool isPreviewClosing)
 {
     if (camera != null)
     {
         if (isPreviewClosing)
         {
             camera.StopPreview();
         }
         camera.Release();
         camera = null;
     }
 }
Example #22
0
 /**
  * Stops camera preview, and releases the camera to the system.
  */
 private void releaseCamera()
 {
     if (VERBOSE)
     {
         Log.Debug(TAG, "releasing camera");
     }
     if (_camera != null)
     {
         _camera.StopPreview();
         _camera.Release();
         _camera = null;
     }
 }
Example #23
0
 /**
  * Stops camera preview, and releases the camera to the system.
  */
 private void releaseCamera()
 {
     if (AppSettings.Logging.SendToConsole)
     {
         Log.Debug(TAG, "releasing camera");
     }
     if (_camera != null)
     {
         _camera.StopPreview();
         _camera.Release();
         _camera = null;
     }
 }
Example #24
0
        protected override void OnPause()
        {
            base.OnPause();

            try
            {
                _camera.StopPreview();
                _camera.Release();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #25
0
        public List <CameraPixels> GetCameraResolution()
        {
            List <CameraPixels> camPixels = new List <CameraPixels>();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                //Lolipop and above
                CameraManager          camMan  = (CameraManager)mactivity.GetSystemService(Context.CameraService);
                string[]               camId   = camMan.GetCameraIdList();
                CameraCharacteristics  camChar = camMan.GetCameraCharacteristics(camId[0]); //0 - mostly for back cam
                StreamConfigurationMap camMap  = (StreamConfigurationMap)camChar.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                Android.Util.Size[]    sizes   = camMap.GetOutputSizes((int)ImageFormatType.Jpeg);

                System.Diagnostics.Debug.WriteLine($"Camera sizes: {sizes.Length}");

                foreach (var size in sizes)
                {
                    //System.Diagnostics.Debug.WriteLine($"Sizes: {size.Width} x {size.Height} = {Convert.ToDouble(size.Width) * Convert.ToDouble(size.Height) / Convert.ToDouble(1024000)} megs");
                    camPixels.Add(new CameraPixels()
                    {
                        Height     = size.Height,
                        Width      = size.Width,
                        Megapixels = Math.Round(Convert.ToDecimal(size.Width) * Convert.ToDecimal(size.Height) / Convert.ToDecimal(1000000), 1)
                    });
                }
            }
            else
            {
                //pre-lolipop
                Android.Hardware.Camera              cam      = Android.Hardware.Camera.Open();
                Android.Hardware.Camera.Parameters   camParam = cam.GetParameters();
                IList <Android.Hardware.Camera.Size> plSizes  = camParam.SupportedPictureSizes;

                foreach (var size in plSizes)
                {
                    System.Diagnostics.Debug.WriteLine($"Sizes: {size.Width} x {size.Height} = {Convert.ToDouble(size.Width) * Convert.ToDouble(size.Height) / Convert.ToDouble(1024000)} megs");
                    camPixels.Add(new CameraPixels()
                    {
                        Height     = size.Height,
                        Width      = size.Width,
                        Megapixels = Math.Round(Convert.ToDecimal(size.Width) * Convert.ToDecimal(size.Height) / Convert.ToDecimal(1000000), 1)
                    });
                }
                cam.Release();
            }

            return(camPixels);
        }
Example #26
0
 public void stop()
 {
     if (camera != null)
     {
         camera.StopPreview();
         camera.SetPreviewCallback(null);
         camera.Release();
         camera = null;
     }
     if (cameraHandlerThread != null)
     {
         cameraHandlerThread.Quit();
         cameraHandlerThread = null;
     }
     LogUtil.i("wtf", "stop");
 }
Example #27
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            // The Surface has been created, acquire the camera and tell it where
            // to draw.
            camera = Camera.Open();

            try
            {
                camera.SetPreviewDisplay(holder);
                camera.SetPreviewCallback(this);
            }
            catch (Exception)
            {
                camera.Release();
                camera = null;
                // TODO: add more exception handling logic here
            }
        }
        private void ReleaseCameraInstance()
        {
            if (_camera != null)
            {
                try
                {
                    _camera.StopPreview();
                }
                catch (System.Exception e)
                {
                }

                _camera.SetPreviewCallback(null);
                _camera.Release();
                _camera   = null;
                _cameraId = -1;
            }
        }
Example #29
0
 public bool isCameraInUse()
 {
     camera = null;
     try
     {
         camera = Android.Hardware.Camera.Open();
     }
     catch (Exception e)
     {
         return(true);
     }
     finally
     {
         if (camera != null)
         {
             camera.Release();
         }
     }
     return(false);
 }
        public void TurnOff()
        {
            if (camera == null)
            {
                camera = Camera.Open();
            }

            if (camera == null)
            {
                Console.WriteLine("Camera failed to initialize");
                return;
            }

            var p = camera.GetParameters();
            var supportedFlashModes = p.SupportedFlashModes;

            if (supportedFlashModes == null)
            {
                supportedFlashModes = new List <string>();
            }

            var flashMode = string.Empty;

            if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
            {
                flashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
            }

            if (!string.IsNullOrEmpty(flashMode))
            {
                p.FlashMode = flashMode;
                camera.SetParameters(p);
            }

            camera.StopPreview();

            //added on 1/3/2016 by aditmer to try to fix the ongoing issue on Android 6.x and the battery drain issue
            camera.Release();
            camera = null;
        }