Example #1
0
        /// почему тело не пустое, как у двух следующих, если его не вызывают??7
        //public Task<bool> SendDrawRectageCoords(float x, float y, float RawX, float RawY, Android.Views.View touchedView, MotionEventActions EventAction)
        //{
        //    //try
        //    //{
        //    //    float XInit = 0.0f;
        //    //    float YInit = 0.0f;
        //    //    switch (EventAction)
        //    //    {
        //    //        case MotionEventActions.Down:
        //    //            XInit = touchedView.GetX() - RawX;
        //    //            YInit = touchedView.GetY() - RawY;
        //    //            break;
        //    //        case MotionEventActions.Move:
        //    //            break;
        //    //        default:
        //    //            break;
        //    //    }

        //    //    return true;
        //    //}
        //    //catch (Exception exp)
        //    //{
        //    //    Console.WriteLine("SendDrawRectageCoords - " + exp.Message);
        //        return false;
        //    //}
        //}  // end of  SendDrawRectageCoords


        /// <summary>
        ///
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            _camera = Android.Hardware.Camera.Open();

            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.SetDisplayOrientation(90);     // возможно тут решение проблемы искажения при переворачивании
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine("OnSurfaceTextureAvailable - " + ex.Message);
            }
        }  // end of OnSurfaceTextureAvailable
    public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
    {
        _camera = Android.Hardware.Camera.Open();

        try
        {
            _camera.SetPreviewTexture(surface);
            _camera.SetDisplayOrientation(90);
            _camera.StartPreview();
        }
        catch (Java.IO.IOException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
Example #3
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            {
                {
                    int cameraCount = Android.Hardware.Camera.NumberOfCameras;
                    int cameraId    = 0;
                    Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
                    for (int camIdx = 0; camIdx < cameraCount; camIdx++)
                    {
                        Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
                        if (cameraInfo.Facing == Android.Hardware.CameraFacing.Front)
                        {
                            camera = Android.Hardware.Camera.Open(camIdx);

                            cameraId = camIdx;
                            break;
                        }
                    }

                    if (camera == null)
                    {
                        camera = Android.Hardware.Camera.Open();
                    }
                }


                var parameters = camera.GetParameters();
                var aspect     = ((decimal)height) / ((decimal)width);

                // Find the preview aspect ratio that is closest to the surface aspect
                //var previewSize = parameters.SupportedPreviewSizes
                //                            .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect))
                //                            .First();

                var previewSize = parameters.SupportedPreviewSizes[0];

                System.Diagnostics.Debug.WriteLine($"Preview sizes: {parameters.SupportedPreviewSizes.Count}");

                mainLayout.LayoutParameters.Height = previewSize.Height;
                mainLayout.LayoutParameters.Width  = previewSize.Width;

                parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
                camera.SetParameters(parameters);

                camera.SetPreviewTexture(surface);
                StartCamera();
            }
        }
Example #4
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int w, int h)
        {
            _camera = Camera.Open();

            _textureView.LayoutParameters = new RelativeLayout.LayoutParams(w, h);

            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #5
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            _camera = Camera.Open();

            _textureView.LayoutParameters =
                new FrameLayout.LayoutParams(width, height);

            try
            {
                _camera.SetPreviewTexture(surface);
                _camera.SetDisplayOrientation(90);
                _camera.StartPreview();
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #6
0
 //Camera stuff
 public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
 {
     if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == (int)Permission.Granted)
     {
         camera = Android.Hardware.Camera.Open();
         cameraSurfaceView.LayoutParameters = new RelativeLayout.LayoutParams(w, h);
         try
         {
             camera.SetPreviewTexture(surface);
             camera.SetDisplayOrientation(90);
             camera.StartPreview();
         }
         catch (Java.IO.IOException ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
Example #7
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            camera = Android.Hardware.Camera.Open();
            var parameters = camera.GetParameters();
            var aspect     = ((decimal)height) / ((decimal)width);

            // Find the preview aspect ratio that is closest to the surface aspect
            var previewSize = parameters.SupportedPreviewSizes
                              .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect))
                              .First();

            System.Diagnostics.Debug.WriteLine($"Preview sizes: {parameters.SupportedPreviewSizes.Count}");

            parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
            camera.SetParameters(parameters);

            camera.SetPreviewTexture(surface);
            StartCamera();
        }
Example #8
0
        public void TurnOn()
        {
            if (camera == null)
            {
                camera = Camera.Open();
            }

            if (camera == null)
            {
                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.FlashModeTorch;
            }

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

            camera.StartPreview();

            try
            {
                camera.SetPreviewTexture(new SurfaceTexture(0));
            }
            catch { }
        }
 public async void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
 {
     if (ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.Camera) != Permission.Granted || ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.RecordAudio) != Permission.Granted || ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.WriteExternalStorage) != Permission.Granted)
     {
         if (ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.Camera) != Permission.Granted)
         {
             ActivityCompat.RequestPermissions(Activity, new string[] { Manifest.Permission.Camera }, 50);
         }
         if (ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.WriteExternalStorage) != Permission.Granted)
         {
             ActivityCompat.RequestPermissions(Activity, new string[] { Manifest.Permission.WriteExternalStorage }, 50);
         }
         if (ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.RecordAudio) != Permission.Granted)
         {
             ActivityCompat.RequestPermissions(Activity, new string[] { Manifest.Permission.RecordAudio }, 50);
         }
         await(Element as VideoCameraPage).Navigation.PopAsync();
     }
     else
     {
         decimal aspect = 0;
         camera = Android.Hardware.Camera.Open();
         var parameters = camera.GetParameters();
         if (GetOrientation())
         {
             aspect = ((decimal)height) / ((decimal)width);
         }
         else
         {
             aspect = ((decimal)width) / ((decimal)height);
         }
         var previewSize = parameters.SupportedPreviewSizes
                           .OrderBy(s => System.Math.Abs(s.Width / (decimal)s.Height - aspect))
                           .First();
         parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
         camera.SetParameters(parameters);
         camera.SetPreviewTexture(surface);
         StartCamera();
     }
 }
Example #10
0
 public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
 {
     _camera = Android.Hardware.Camera.Open();
     _textureView.LayoutParameters = new FrameLayout.LayoutParams(w, h);
     _camera.SetPreviewTexture(surface);
     _camera.StartPreview();
     try
     {
         Toast.MakeText(this, "About to take picture", ToastLength.Short).Show();
         _camera.TakePicture(null, null, this);
         Toast.MakeText(this, "Finished pic", ToastLength.Short).Show();
         _camera = Android.Hardware.Camera.Open();
         _textureView.LayoutParameters = new FrameLayout.LayoutParams(w, h);
         _camera.SetPreviewTexture(surface);
         _camera.StartPreview();
         Toast.MakeText(this, "This shit again!", ToastLength.Short).Show();
     }
     catch (Exception e)
     {
         Toast.MakeText(this, e.ToString(), ToastLength.Long).Show();
     }
 }
Example #11
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            try {
                _camera = Android.Hardware.Camera.Open(GetFrontCameraId());
                _camera.SetDisplayOrientation(90);

                var pictureSize = _camera.GetParameters().PictureSize;
                var previewSize = _camera.GetParameters().PreviewSize;

                // Need to flip around width and height because of the rotation
                textureView.LayoutParameters = new RelativeLayout.LayoutParams(pictureSize.Height, pictureSize.Width);
                var aspectRatio = ((double)pictureSize.Height) / ((double)pictureSize.Width);

                var lp = this.gameoverOverlayLayer.LayoutParameters;
                lp.Height = (int)(Resources.DisplayMetrics.HeightPixels * 0.6);
                lp.Width  = (int)(lp.Height * aspectRatio);
                this.gameoverOverlayLayer.LayoutParameters = lp;

                _camera.SetPreviewTexture(surface);
                _camera.StartPreview();
            }  catch (Java.IO.IOException ex) {
                System.Console.WriteLine(ex.Message);
            }
        }
Example #12
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))
                            {
                                try
                                {
                                    cameraManager.SetTorchMode(id, switchOn);
                                    break;
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine($"Unable to SetTorchMode on {id}: {ex.Message}");
                                }
                            }
                        }
                    }
                    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 #13
0
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            {
                {
                    int cameraCount = Android.Hardware.Camera.NumberOfCameras;
                    int cameraId    = 0;
                    Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
                    for (int camIdx = 0; camIdx < cameraCount; camIdx++)
                    {
                        Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
                        if (cameraInfo.Facing == Android.Hardware.CameraFacing.Front)
                        {
                            camera = Android.Hardware.Camera.Open(camIdx);

                            cameraId = camIdx;
                            break;
                        }
                    }

                    if (camera == null)
                    {
                        camera = Android.Hardware.Camera.Open();
                    }
                }


                var parameters = camera.GetParameters();
                var aspect     = ((decimal)height) / ((decimal)width);

                // Find the preview aspect ratio that is closest to the surface aspect
                //var previewSize = parameters.SupportedPreviewSizes
                //                            .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect))
                //                            .First();

                var previewSize = parameters.SupportedPreviewSizes[2];
                //     mainLayout.LayoutParameters.Height = previewSize.Height;
                //     mainLayout.LayoutParameters.Width = previewSize.Width;

                parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surface);
                StartCamera();


                //caemra page render
                Task.Run(() =>
                {
                    while (camera != null)
                    {
                        if (NetProcess.JpegStream.Count == 0)
                        {
                            continue;
                        }

                        MemoryStream ms;
                        if (NetProcess.JpegStream.TryDequeue(out ms) == true)
                        {
                            if (ms == null)
                            {
                                continue;
                            }

                            _context.Post(delegate
                            {
                                var bitmap = BitmapFactory.DecodeByteArray(ms?.ToArray(), 0, ms.ToArray().Length);

                                imageView.SetImageBitmap(bitmap);
                            }, null);
                        }
                        Thread.Sleep(100);
                    }
                });


                //caemra page render
                Task.Run(() =>
                {
                    audiomgr?.record();
                });


                Task.Run(() =>
                {
                    while (audiomgr != null)
                    {
                        MemoryStream ms;
                        if (NetProcess.AudioStream.TryDequeue(out ms) == true)
                        {
                            if (ms == null)
                            {
                                continue;
                            }

                            //      _context.Post(delegate
                            //       {
                            audiomgr?.play(ms.ToArray());

                            //    }, null);
                        }

                        Thread.Sleep(1);
                    }
                });
            }
        }
Example #14
0
        void SetupUserInterface()
        {
            var metrics = Resources.DisplayMetrics;

            half_width  = metrics.WidthPixels / 2;
            half_height = metrics.HeightPixels / 4;


            mainLayout = new RelativeLayout(Context);
            mainLayout.SetBackgroundColor(Color.Black);

            /////////////////////////////////////////////////////////////////////////////////
            liveView = new TextureView(Context);

            RelativeLayout.LayoutParams liveViewParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MatchParent,
                RelativeLayout.LayoutParams.MatchParent);

            liveViewParams.Height     = half_height;
            liveViewParams.Width      = half_width;
            liveView.LayoutParameters = liveViewParams;
            liveView.Rotation         = 90;
            mainLayout.AddView(liveView);

            //TextView textview1 = new TextView(Context);
            //textview1.Text = "";
            //textview1.SetX(half_width / 2);
            //textview1.SetY(half_height + 10);
            //textview1.SetTextColor(Color.White);
            //mainLayout.AddView(textview1);
            ///////////////////////////////////////////////////////////////////////////////

            ///////////////////////////////////////////////////////////////////////////////
            AddImageView(0);
            AddImageView(1);
            AddImageView(2);
            AddImageView(3);
            AddImageView(4);
            AddImageView(5);

            //중앙 스크린
            AddImageView(6, metrics.WidthPixels, half_height * 2);

            ///////////////////////////////////////////////////////////////////////////////
            textViewMain = new TextView(Context);
            RelativeLayout.LayoutParams TextViewParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WrapContent,
                RelativeLayout.LayoutParams.WrapContent);
            textViewMain.LayoutParameters = TextViewParams;
            textViewMain.Text             = "123124";
            textViewMain.SetTextColor(Color.White);
            textViewMain.Click += async(s, e) =>
            {
                textViewMain.Text = "";
            };
            mainLayout.AddView(textViewMain);
            ///////////////////////////////////////////////////////////////////////////////
            ///

            ///////////////////////////////////////////////////////////////////////////////
            mainScreenButton = new Button(Context);
            RelativeLayout.LayoutParams ButtonParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WrapContent,
                RelativeLayout.LayoutParams.WrapContent);
            mainScreenButton.LayoutParameters = ButtonParams;
            mainScreenButton.Text             = "Hide";
            mainScreenButton.Click           += async(s, e) =>
            {
                ImageView view;
                if (imageViewDic.TryGetValue(6, out view) == true)
                {
                    if (view.Visibility == ViewStates.Visible)
                    {
                        view.Visibility       = ViewStates.Invisible;
                        mainScreenButton.Text = "Show";
                    }
                    else
                    {
                        view.Visibility       = ViewStates.Visible;
                        mainScreenButton.Text = "Hide";
                    }
                }
            };
            mainLayout.AddView(mainScreenButton);

            ///////////////////////////////////////////////////////////////////////////////
            qualityUp = new Button(Context);
            qualityUp.LayoutParameters = ButtonParams;
            qualityUp.Text             = "Up";
            qualityUp.Click           += async(s, e) =>
            {
                quality++;
                if (quality > 100)
                {
                    quality = 100;
                }

                qualityUp.Text = quality.ToString();
            };
            mainLayout.AddView(qualityUp);
            ///////////////////////////////////////////////////////////////////////////////
            qualityDown = new Button(Context);
            qualityDown.LayoutParameters = ButtonParams;
            qualityDown.Text             = "Down";
            qualityDown.Click           += async(s, e) =>
            {
                quality--;
                if (quality < 0)
                {
                    quality = 0;
                }

                qualityUp.Text = quality.ToString();
            };
            mainLayout.AddView(qualityDown);
            ///////////////////////////////////////////////////////////////////////////////
            exitButton = new Button(Context);
            exitButton.LayoutParameters = ButtonParams;
            exitButton.Text             = "EXIT";
            exitButton.Click           += async(s, e) =>
            {
                var page = Element as CameraPage;

                PopupNavigation.Instance.PopAsync();
            };
            mainLayout.AddView(exitButton);
            ////////////////////////////////////////////////////////////DrawLayout///////////////////
            switchButton = new Button(Context);
            switchButton.LayoutParameters = ButtonParams;
            switchButton.Text             = "Switch";
            switchButton.Click           += async(s, e) =>
            {
                StopCamera();

                if (currentFacing == Android.Hardware.CameraFacing.Front)
                {
                    currentFacing = Android.Hardware.CameraFacing.Back;
                }
                else
                {
                    currentFacing = Android.Hardware.CameraFacing.Front;
                }

                {
                    int cameraCount = Android.Hardware.Camera.NumberOfCameras;
                    int cameraId    = 0;
                    Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
                    for (int camIdx = 0; camIdx < cameraCount; camIdx++)
                    {
                        Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
                        if (cameraInfo.Facing == currentFacing)
                        {
                            camera   = Android.Hardware.Camera.Open(camIdx);
                            cameraId = camIdx;
                            break;
                        }
                    }

                    if (camera == null)
                    {
                        camera = Android.Hardware.Camera.Open();
                    }

                    var parameters = camera.GetParameters();

                    // Find the preview aspect ratio that is closest to the surface aspect
                    //var previewSize = parameters.SupportedPreviewSizes
                    //                            .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect))
                    //                            .First();

                    var previewSize = parameters.SupportedPreviewSizes[2];
                    //     mainLayout.LayoutParameters.Height = previewSize.Height;
                    //     mainLayout.LayoutParameters.Width = previewSize.Width;

                    parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(_surface);
                    StartCamera();
                }
            };
            mainLayout.AddView(switchButton);

            ////////////////////////////////////////////////////////////DrawLayout///////////////////

            AddView(mainLayout);
        }
Example #15
0
        void SetupUserInterface()
        {
            var metrics = Resources.DisplayMetrics;

            half_width  = metrics.WidthPixels / 2;
            half_height = metrics.HeightPixels / 4;


            mainLayout = new RelativeLayout(Context);
            mainLayout.SetBackgroundColor(Color.Black);

            /////////////////////////////////////////////////////////////////////////////////
            liveView = new TextureView(Context);

            RelativeLayout.LayoutParams liveViewParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MatchParent,
                RelativeLayout.LayoutParams.MatchParent);

            liveViewParams.Height     = half_height;
            liveViewParams.Width      = half_width;
            liveView.LayoutParameters = liveViewParams;
            liveView.Rotation         = 90;
            mainLayout.AddView(liveView);

            //TextView textview1 = new TextView(Context);
            //textview1.Text = "";
            //textview1.SetX(half_width / 2);
            //textview1.SetY(half_height + 10);
            //textview1.SetTextColor(Color.White);
            //mainLayout.AddView(textview1);
            ///////////////////////////////////////////////////////////////////////////////

            ///////////////////////////////////////////////////////////////////////////////
            AddImageView(0);
            AddImageView(1);
            AddImageView(2);
            AddImageView(3);
            AddImageView(4);
            AddImageView(5);
            ///////////////////////////////////////////////////////////////////////////////
            exitButton = new Button(Context);
            RelativeLayout.LayoutParams ButtonParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WrapContent,
                RelativeLayout.LayoutParams.WrapContent);
            ButtonParams.Height         = 150;
            ButtonParams.Width          = 150;
            exitButton.LayoutParameters = ButtonParams;
            exitButton.Text             = "EXIT";
            exitButton.Click           += async(s, e) =>
            {
                var page = Element as CameraPage;

                PopupNavigation.Instance.PopAsync();
            };
            mainLayout.AddView(exitButton);
            ////////////////////////////////////////////////////////////DrawLayout///////////////////
            switchButton = new Button(Context);
            switchButton.LayoutParameters = ButtonParams;
            switchButton.Text             = "Switch";
            switchButton.Click           += async(s, e) =>
            {
                StopCamera();

                if (currentFacing == Android.Hardware.CameraFacing.Front)
                {
                    currentFacing = Android.Hardware.CameraFacing.Back;
                }
                else
                {
                    currentFacing = Android.Hardware.CameraFacing.Front;
                }

                {
                    int cameraCount = Android.Hardware.Camera.NumberOfCameras;
                    int cameraId    = 0;
                    Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo();
                    for (int camIdx = 0; camIdx < cameraCount; camIdx++)
                    {
                        Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
                        if (cameraInfo.Facing == currentFacing)
                        {
                            camera   = Android.Hardware.Camera.Open(camIdx);
                            cameraId = camIdx;
                            break;
                        }
                    }

                    if (camera == null)
                    {
                        camera = Android.Hardware.Camera.Open();
                    }

                    var parameters = camera.GetParameters();

                    // Find the preview aspect ratio that is closest to the surface aspect
                    //var previewSize = parameters.SupportedPreviewSizes
                    //                            .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect))
                    //                            .First();

                    var previewSize = parameters.SupportedPreviewSizes[2];
                    //     mainLayout.LayoutParameters.Height = previewSize.Height;
                    //     mainLayout.LayoutParameters.Width = previewSize.Width;

                    parameters.SetPreviewSize(previewSize.Width, previewSize.Height);
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(_surface);
                    StartCamera();
                }
            };
            mainLayout.AddView(switchButton);

            ////////////////////////////////////////////////////////////DrawLayout///////////////////



            AddView(mainLayout);
        }