Example #1
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 #2
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 #3
0
        public async Task GetPhoto()
        {
            _camera = Camera.Open();
            var parameters = _camera.GetParameters();

            var sizes = parameters.SupportedPictureSizes;

            int index = 0;

            for (int i = 0; i < sizes.Count; i++)
            {
                if (sizes[i].Width > 1200 && sizes[i].Width < 1300)
                {
                    index = i;
                }
            }

            parameters.SetPictureSize(sizes[index].Width, sizes[index].Height);
            parameters.SetRotation(90);
            parameters.SceneMode     = Camera.Parameters.SceneModeAuto;
            parameters.WhiteBalance  = Camera.Parameters.WhiteBalanceAuto;
            parameters.FocusMode     = Camera.Parameters.FocusModeContinuousPicture;
            parameters.PictureFormat = ImageFormatType.Jpeg;
            parameters.JpegQuality   = 100;
            _camera.SetParameters(parameters);
            _camera.SetPreviewCallback(this);
            _camera.Lock();
            SurfaceTexture st = new SurfaceTexture(100);

            _camera.SetPreviewTexture(st);
            _camera.StartPreview();

            await TakePicture();
        }
Example #4
0
        private void StopRecording()
        {
            timer.Stop();
            timer.Visibility = ViewStates.Invisible;
            //--------------------------------------------------
            isVideoStarted = false;
            recorder.Stop();
            recorder.Release();
            camera.Lock();
            camera.StopPreview();
            camera.Release();


            FileInputStream inputStream = null;

            inputStream = new FileInputStream(path);
            byte[] bytes;
            byte[] buffer = new byte[8192];
            int    bytesRead;


            ByteArrayOutputStream output = new ByteArrayOutputStream();

            try
            {
                while ((bytesRead = inputStream.Read(buffer)) != -1)
                {
                    output.Write(buffer, 0, bytesRead);
                }
            }
            catch (Java.Lang.Exception exception)
            {
                //  e.PrintStackTrace();
            }
            bytes = output.ToByteArray();
            string attachedFile = Base64.EncodeToString(bytes, Base64.Default);

            captureButton.RemoveFromParent();

            //on the CameraPage you can get base64 and video path
            MessagingCenter.Send <string, string>("VideoBase64Ready", "VideoIsReady", attachedFile);

            MessagingCenter.Send <string, string>("VideoPathReady", "VideoPathReady", path);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            var metrics = new DisplayMetrics();
            WindowManager.DefaultDisplay.GetRealMetrics(metrics);

            ScreenX = metrics.WidthPixels;
            ScreenY = metrics.HeightPixels;

            number = 0;
            SetContentView(Resource.Layout.CameraTakePicScreen);
            isRunning = false;
            var header = FindViewById<TextView>(Resource.Id.txtFirstScreenHeader);
            var btns = FindViewById<ImageView>(Resource.Id.imgNewUserHeader);
            var relLayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1);
            ImageHelper.setupTopPanel(btns, header, relLayout, header.Context);

            Header.headertext = Application.Context.Resources.GetString(Resource.String.photoTitle);
            Header.fontsize = 32f;
            ImageHelper.fontSizeInfo(header.Context);
            header.SetTextSize(Android.Util.ComplexUnitType.Dip, Header.fontsize);
            header.Text = Header.headertext;

            var surface = FindViewById<SurfaceView>(Resource.Id.surfaceCameraView);

            holder = surface.Holder;
            holder.AddCallback(this);
            context = surface.Context;

            var takePicture = FindViewById<ImageButton>(Resource.Id.btnCamera);
            takePicture.Tag = 1;
            var flipView = FindViewById<ImageButton>(Resource.Id.imgFlipView);
            flipView.Tag = 2;
            var returnBack = FindViewById<ImageButton>(Resource.Id.imgBack);
            returnBack.Tag = 0;
            var bottom = FindViewById<LinearLayout>(Resource.Id.bottomHolder);

            var btn = new ImageButton[3];
            btn[0] = returnBack;
            btn[1] = takePicture;
            btn[2] = flipView;

            ImageHelper.setupButtonsPosition(btn, bottom, context);

            var cameraInfo = new Android.Hardware.Camera.CameraInfo();
            camera = null;

            int cameraCount = Android.Hardware.Camera.NumberOfCameras;
            if (cameraCount == 1)
                flipView.Visibility = ViewStates.Invisible;
            else
            {
                flipView.Click += delegate
                {
                    if (isRunning)
                    {
                        camera.StopPreview();
                        isRunning = false;
                        camera.Unlock();

                        if (cameraCount > 1 && camID < cameraCount - 1)
                            camID++;
                        else
                            camID--;

                        camera = Android.Hardware.Camera.Open(camID);
                        isRunning = true;

                        camera.Lock();
                        camera.StartPreview();
                    }
                };
            }
            takePicture.Click += delegate
            {
                var p = camera.GetParameters();
                p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
                camera.SetParameters(p);
                camera.TakePicture(this, this, this);
            };

            returnBack.Click += (object sender, EventArgs e) =>
            {
                var resultData = new Intent();
                resultData.PutExtra("filename", fullFilename);
                SetResult(!string.IsNullOrEmpty(fullFilename) ? Result.Ok : Result.Canceled, resultData);
                Finish();
            };
        }
Example #6
0
 public void SurfaceCreated(ISurfaceHolder holder)
 {
     try
     {
         // if only front camera, get it
         camera = Camera.Open(0);
         Camera.Parameters p = camera.GetParameters();
         p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
         camera.EnableShutterSound(true);
         // fix camera rotation
         camera.SetDisplayOrientation(0);
         camera.SetParameters(p);
         camera.SetPreviewCallback(this);
         camera.Lock();
         camera.SetPreviewDisplay(holder);
         camera.StartPreview();
     }
     catch (Java.IO.IOException e)
     {
     }
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            number = 0;
            SetContentView(Resource.Layout.CameraTakePicScreen);
            isRunning = false;
            TextView header = FindViewById<TextView>(Resource.Id.txtFirstScreenHeader);
            ImageView btns = FindViewById<ImageView>(Resource.Id.imgNewUserHeader);
            RelativeLayout relLayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1);
            ImageHelper.setupTopPanel(btns, header, relLayout, header.Context);

            Header.headertext = Application.Context.Resources.GetString(Resource.String.photoTitle);
            Header.fontsize = 36f;
            ImageHelper.fontSizeInfo(header.Context);
            header.SetTextSize(Android.Util.ComplexUnitType.Dip, Header.fontsize);
            header.Text = Header.headertext;

            SurfaceView surface = FindViewById<SurfaceView>(Resource.Id.surfaceCameraView);

            holder = surface.Holder;
            holder.AddCallback(this);
            holder.SetType(Android.Views.SurfaceType.PushBuffers);
            context = surface.Context;

            ImageButton takePicture = FindViewById<ImageButton>(Resource.Id.btnCamera);
            takePicture.Tag = 1;
            ImageButton flipView = FindViewById<ImageButton>(Resource.Id.imgFlipView);
            flipView.Tag = 2;
            ImageButton returnBack = FindViewById<ImageButton>(Resource.Id.imgBack);
            returnBack.Tag = 0;
            LinearLayout bottom = FindViewById<LinearLayout>(Resource.Id.bottomHolder);

            ImageButton[] btn = new ImageButton[3];
            btn [0] = returnBack;
            btn [1] = takePicture;
            btn [2] = flipView;

            ImageHelper.setupButtonsPosition(btn, bottom, context);

            int back = (int)Android.Hardware.CameraFacing.Back;
            int front = (int)Android.Hardware.CameraFacing.Front;

            Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
            camera = null;

            int cameraCount = Android.Hardware.Camera.NumberOfCameras;
            if (cameraCount == 1)
                flipView.Visibility = ViewStates.Invisible;
            else
            {
                flipView.Click += delegate
                {
                    if (isRunning)
                    {
                        camera.StopPreview();
                        isRunning = false;
                        camera.Unlock();
                        //camera.Release();

                        if (cameraCount > 1 && camID < cameraCount - 1)
                            camID++;
                        else
                            camID--;

                        camera = Android.Hardware.Camera.Open(camID);
                        isRunning = true;

                        camera.Lock();
                        camera.StartPreview();
                    }
                };
            }
            takePicture.Click += delegate
            {
                Android.Hardware.Camera.Parameters p = camera.GetParameters();
                p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
                camera.SetParameters(p);
                camera.TakePicture(this, this, this);
            };

            returnBack.Click += (object sender, EventArgs e) =>
            {
                Intent resultData = new Intent();
                resultData.PutExtra("filename", fullFilename);
                if (fullFilename != "")
                    SetResult(Result.Ok, resultData);
                else
                    SetResult(Result.Canceled, resultData);
                Finish();
            };
        }