public void StartPreview()
        {
            if (liveTextureView.SurfaceTexture == null)
            {
                return;
            }

            var texture = liveTextureView.SurfaceTexture;

            texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
            var surface = new Surface(texture);

            previewBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            previewBuilder.AddTarget(surface);

            CameraDevice.CreateCaptureSession(new List <Surface> {
                surface
            }, new CameraCaptureStateListener
            {
                OnConfigureFailedAction = (CameraCaptureSession session) =>
                {
                },
                OnConfiguredAction = (CameraCaptureSession session) =>
                {
                    previewSession = session;
                    previewBuilder.Set(CaptureRequest.ControlMode, new Java.Lang.Integer((int)ControlMode.Auto));

                    var thread = new HandlerThread("CameraPicture");
                    thread.Start();
                    var backgroundHandler = new Handler(thread.Looper);
                    previewSession.SetRepeatingRequest(previewBuilder.Build(), null, backgroundHandler);
                }
            }, null);
        }
예제 #2
0
        // Creates a new {@link CameraCaptureSession} for camera preview.
        public void CreateCameraPreviewSession()
        {
            try
            {
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                if (texture == null)
                {
                    throw new IllegalStateException("texture is null");
                }

                // We configure the size of default buffer to be the size of camera preview we want.
                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                // This is the output Surface we need to start preview.
                Surface surface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface.
                MPreviewRequestBuilder = MCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                MPreviewRequestBuilder.AddTarget(surface);

                // Here, we create a CameraCaptureSession for camera preview.
                List <Surface> surfaces = new List <Surface> {
                    surface
                };
                MCameraDevice.CreateCaptureSession(surfaces, new CameraCaptureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
예제 #3
0
#pragma warning restore CS0618 // Type or member is obsolete
        #endregion

        public void StartPreview()
        {
            if (mCameraDevice == null || !textureView.IsAvailable || mPreviewSize == null)
            {
                return;
            }
            try
            {
                SurfaceTexture texture = textureView.SurfaceTexture;
                System.Diagnostics.Debug.Assert(texture != null);

                // We configure the size of the default buffer to be the size of the camera preview we want
                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                // This is the output Surface we need to start the preview
                previewSurface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface
                mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                mPreviewBuilder.AddTarget(previewSurface);

                // Here, we create a CameraCaptureSession for camera preview.
                mCameraDevice.CreateCaptureSession(new List <Surface>()
                {
                    previewSurface
                },
                                                   new CameraCaptureStateListener()
                {
                    OnConfigureFailedAction = (CameraCaptureSession session) =>
                    {
                        Activity activity = Activity;
                        if (activity != null)
                        {
                            Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
                        }
                    },
                    OnConfiguredAction = (CameraCaptureSession session) =>
                    {
                        mPreviewSession = session;
                        UpdatePreview();
                    }
                },
                                                   null);

                takePhotoButton.Enabled = true;
            }
            catch (CameraAccessException ex)
            {
                Log.WriteLine(LogPriority.Info, "Camera2BasicFragment", ex.StackTrace);
            }
        }
예제 #4
0
        public void startPreview()
        {
            if (null == cameraDevice || !activity.textureView.IsAvailable || null == previewSize)
            {
                return;
            }

            try
            {
                SetUpRecoder();
                SurfaceTexture texture = activity.textureView.SurfaceTexture;
                texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
                previewBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Record);
                var surfaces       = new List <Surface>();
                var previewSurface = new Surface(texture);
                surfaces.Add(previewSurface);
                previewBuilder.AddTarget(previewSurface);

                var recorderSurface = mediaRecorder.Surface;
                surfaces.Add(recorderSurface);
                previewBuilder.AddTarget(recorderSurface);

                cameraDevice.CreateCaptureSession(surfaces, new PreviewCaptureStateCallback(activity, this), backgroundHandler);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (Java.IO.IOException e)
            {
                e.PrintStackTrace();
            }
        }
예제 #5
0
        public async Task <ICameraPreview> OpenWithPreviewAsync(Xamarin.Forms.Size previewRequestSize)
        {
            await OpenAsync(true);

            var stateCallback = new StateCallback();

            stateCallback.Configured      += SessionConfigured;
            stateCallback.ConfigureFailed += SessionConfigureFailed;
            var previewSurface = _cameraPreview.CreateSurface(previewRequestSize);

            _previewRequestBuilder.AddTarget(previewSurface);
            _previewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);

            var characteristics = _manager.GetCameraCharacteristics(_cameraDevice.Id);
            var map             = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);

            // ReSharper disable once CoVariantArrayConversion
            _imageSize = (Size)Collections.Max(
                Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                new CompareSizesByArea());

            _imageReader = ImageReader.NewInstance(_imageSize.Width, _imageSize.Height,
                                                   ImageFormatType.Jpeg, /* maxImages */ 2);
            _imageAvailableListener = new ImageAvailableListener();
            _imageAvailableListener.ImageAvailable += CaptureAvailable;
            _imageReader.SetOnImageAvailableListener(_imageAvailableListener, _backgroundThread.Handler);
            var surfaces = new List <Surface> {
                previewSurface, _imageReader.Surface
            };

            _cameraDevice.CreateCaptureSession(surfaces, stateCallback, null);
            return(_cameraPreview);
        }
예제 #6
0
        public async void CreateCaptureSession()
        {
            int totalWaitTime = 0;
            int increment     = 100;

            //wait for the camera device to initialize
            while (_cameraDevice == null)
            {
                await Task.Delay(increment);

                totalWaitTime = totalWaitTime + increment;
                if (totalWaitTime > _maxWaitTimeMilliseconds)
                {
                    throw new Exception(String.Format("Timeout ({0} milliseconds) waiting for camera device to be created.", _maxWaitTimeMilliseconds));
                }
            }

            var surface = _yuvImageReader.Get().Surface;
            //surface.DescribeContents()
            CameraCaptureSessionCallback ccsc =
                new CameraCaptureSessionCallback(_cameraDevice, surface, _cameraStateLock, _backgroundHandler, TAG);

            ccsc.OnConfigurationComplete += (sender, args) =>
            {
                _state          = STATE_PREVIEW;
                _captureSession = args;
            };
            _cameraDevice.CreateCaptureSession(new List <Surface>()
            {
                surface
            }, ccsc, _backgroundHandler);
        }
예제 #7
0
        /// <summary>
        /// Обработка событий от камеры
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="state"></param>
        private void _cameraStateChange(CameraDevice camera, CameraState state)
        {
            switch (state)
            {
            case CameraState.Opened:
                var surfaceTexture = Texture.SurfaceTexture;
                surfaceTexture.SetDefaultBufferSize(1920, 1080);
                var surface = new Surface(surfaceTexture);

                //переод. событие для обновл. картинки
                var captureRequestBuilder = camera.CreateCaptureRequest(CameraTemplate.Preview);
                captureRequestBuilder.AddTarget(surface);

                camera.CreateCaptureSession(new List <Surface> {
                    surface
                }, new CamaraConfigurationCallback(_cameraStateChange, captureRequestBuilder.Build()), null);
                break;

            case CameraState.Disconected:
                camera.Close();
                break;

            case CameraState.Configurated:
                break;
            }
        }
        public void StartPreview()
        {
            if (CameraDevice == null || !_cameraTexture.IsAvailable || _previewSize == null)
            {
                return;
            }

            var texture = _cameraTexture.SurfaceTexture;

            texture.SetDefaultBufferSize(_previewSize.Width, _previewSize.Height);

            var surface = new Surface(texture);

            _previewBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            _previewBuilder.AddTarget(surface);

            List <Surface> surfaces = new List <Surface>();

            surfaces.Add(surface);
            surfaces.Add(_imageReader.Surface);

            CameraDevice.CreateCaptureSession(surfaces,
                                              new CameraCaptureStateListener
            {
                OnConfigureFailedAction = session =>
                {
                },
                OnConfiguredAction = session =>
                {
                    _previewSession = session;
                    UpdatePreview();
                }
            },
                                              _backgroundHandler);
        }
            public override void OnOpened(CameraDevice camera)
            {
                // プレビュー用のSurfaceViewをリストに登録
                SurfaceView surfaceView = m_parent.m_surfaceView;

                ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams)surfaceView.LayoutParameters;
                lp.Width  = 320; //横幅
                lp.Height = 240; //縦幅
                surfaceView.LayoutParameters = lp;

                surfaceView.Holder.SetFixedSize(240, 320);//縦で持つときはwidth height が逆

                List <Surface> surfaceList = new List <Surface>();

                surfaceList.Add(surfaceView.Holder.Surface);

                try
                {
                    // プレビューリクエストの設定(SurfaceViewをターゲットに)
                    m_parent.m_PreviewBuilder = camera.CreateCaptureRequest(CameraTemplate.Preview);
                    m_parent.m_PreviewBuilder.AddTarget(surfaceView.Holder.Surface);

                    // キャプチャーセッションの開始(セッション開始後に第2引数のコールバッククラスが呼ばれる)
                    camera.CreateCaptureSession(surfaceList, new CameraCaptureSessionCallback(m_parent), null);
                }
                catch (CameraAccessException e)
                {
                    // エラー時の処理を記載
                }
            }
예제 #10
0
        public void CameraOpened()
        {
            mPreviewRequestBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            List <Surface> Targets = new List <Surface>();

            Targets.Add(multiReader.Surface);
            mCameraDevice.CreateCaptureSession(Targets, StateCallback, null);
        }
        /** Creates a new {@link CameraCaptureSession} for camera preview. */
        private void createCameraPreviewSession()
        {
            try
            {
                SurfaceTexture texture = textureView.SurfaceTexture;
                //  assert texture != null;

                // We configure the size of default buffer to be the size of camera preview we want.
                texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);

                // This is the output Surface we need to start preview.
                Surface surface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface.
                previewRequestBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                previewRequestBuilder.AddTarget(surface);
                StateCallback call = new StateCallback();

                call.OnConfiguredHandler += (sender, e) =>
                {
                    if (null == cameraDevice)
                    {
                        return;
                    }

                    // When the session is ready, we start displaying the preview.
                    captureSession = e;// cameraCaptureSession;
                    try
                    {
                        // Auto focus should be continuous for camera preview.
                        previewRequestBuilder.Set(
                            CaptureRequest.ControlAeMode,
                            (int)ControlAFMode.ContinuousPicture);

                        // ly, we start displaying the camera preview.
                        previewRequest = previewRequestBuilder.Build();
                        CaptureCallback captureCallback = new CaptureCallback();

                        captureSession.SetRepeatingRequest(previewRequest, captureCallback, backgroundHandler);
                    }
                    catch (CameraAccessException ex)
                    {
                        Log.Error(TAG, "Failed to set up config to capture Camera", e);
                    }
                };


                // Here, we create a CameraCaptureSession for camera preview.
                cameraDevice.CreateCaptureSession(new System.Collections.Generic.List <Surface>()
                {
                    surface
                }, call, null);
            }
            catch (CameraAccessException e)
            {
                Log.Error(TAG, "Failed to preview Camera", e);
            }
        }
        public override void OnOpened(CameraDevice camera)
        {
            System.Diagnostics.Debug.WriteLine("Camera ouverte");

            _builder = camera.CreateCaptureRequest(CameraTemplate.Preview);
            _builder.AddTarget(_sv);
            _ccssc = new CameraCaptureSessionCallbackU(_builder);
            camera.CreateCaptureSession(ls, _ccssc, new Handler());
        }
예제 #13
0
        public override void OnOpened(CameraDevice camera)
        {
            CaptureRequest.Builder builder = camera.CreateCaptureRequest(CameraTemplate.Preview);
            builder.AddTarget(_surface);
            builder.AddTarget(_reader.Surface);
            CaptureRequest captureRequest = builder.Build();

            camera.CreateCaptureSession(new List <Surface> {
                _surface, _reader.Surface
            }, new MySessionCallback(captureRequest, _cameraPreviewView, _reader), new Handler(msg => { }));
        }
예제 #14
0
 private void CaptureSession(List <Surface> surfaces)
 {
     try
     {
         mCameraDevice.CreateCaptureSession(surfaces, new CameraCaptureSessionStateCallback(this), mCameraHandler);
     }
     catch (System.Exception e)
     {
         Log.Debug(TAG, "CaptureSession error");
     }
 }
예제 #15
0
        //Start the camera preview
        public void startPreview()
        {
            if (null == camera_device || !texture_view.IsAvailable || null == preview_size)
            {
                return;
            }

            try {
                SurfaceTexture texture = texture_view.SurfaceTexture;
                //Assert.IsNotNull(texture);
                texture.SetDefaultBufferSize(preview_size.Width, preview_size.Height);
                preview_builder = camera_device.CreateCaptureRequest(CameraTemplate.Preview);
                Surface surface  = new Surface(texture);
                var     surfaces = new List <Surface>();
                surfaces.Add(surface);
                preview_builder.AddTarget(surface);
                camera_device.CreateCaptureSession(surfaces, new PreviewCaptureStateListener(this), null);
            } catch (CameraAccessException e) {
                e.PrintStackTrace();
            }
        }
예제 #16
0
        public void StartPreview()
        {
            if (cameraDevice != null && autoFitTextureView.IsAvailable && previewSize != null)
            {
                try
                {
                    var texture = autoFitTextureView.SurfaceTexture;
                    System.Diagnostics.Debug.Assert(texture != null);
                    texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);

                    var surface = new Surface(texture);

                    captureRequestBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                    captureRequestBuilder.AddTarget(surface);

                    cameraDevice.CreateCaptureSession(new List <Surface>()
                    {
                        surface
                    },
                                                      new CameraCaptureStateListener()
                    {
                        OnConfigureFailedAction = (CameraCaptureSession session) =>
                        {
                        },
                        OnConfiguredAction = (CameraCaptureSession session) =>
                        {
                            cameraCaptureSession = session;
                            UpdatePreview();
                        }
                    },
                                                      null);
                }
                catch (Java.Lang.Exception error)
                {
                    ShowToastMessage("Failed to start preview");
                    DebugMessage("ErrorMessage: \n" + error.Message + "\n" + "Stacktrace: \n " + error.StackTrace);
                }
            }
        }
예제 #17
0
            public override void OnOpened(CameraDevice camera)
            {
                // request a preview capture of the camera, and notify the session
                // that we will be rendering to the image reader, as well as the preview surface.
                _renderer.Camera = camera;
                var surface = new Surface(_renderer.Surface);

                _renderer.Builder = camera.CreateCaptureRequest(CameraTemplate.Preview);
                _renderer.Builder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
                _renderer.Builder.AddTarget(surface);
                camera.CreateCaptureSession(new List <Surface> {
                    surface, _renderer.Reader.Surface
                }, _renderer.SessionCallback, null);
            }
예제 #18
0
        // Creates a new {@link CameraCaptureSession} for camera preview.
        public void CreateCameraPreviewSession(bool builderexists = false)
        {
            try
            {
                var texture = mTextureView.SurfaceTexture;
                if (texture == null)
                {
                    throw new IllegalStateException("texture is null");
                }

                // We configure the size of default buffer to be the size of camera preview we want.
                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                // This is the output Surface we need to start preview.
                var surface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface.
                if (!builderexists)
                {
                    mPreviewRequestBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                }

                //mPreviewRequestBuilder.Set(CaptureRequest.ControlAeTargetFpsRange, new Android.Util.Range(30, 120));

                mPreviewRequestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.On);
                mPreviewRequestBuilder.Set(CaptureRequest.ControlAwbMode, (int)ControlAwbMode.Auto);
                mPreviewRequestBuilder.Set(CaptureRequest.ControlAePrecaptureTrigger, (int)ControlAEPrecaptureTrigger.Start);
                mPreviewRequestBuilder.Set(CaptureRequest.LensOpticalStabilizationMode, (int)LensOpticalStabilizationMode.On);
                mPreviewRequestBuilder.Set(CaptureRequest.EdgeMode, (int)EdgeMode.Fast);
                mPreviewRequestBuilder.Set(CaptureRequest.ShadingMode, (int)ShadingMode.HighQuality);
                mPreviewRequestBuilder.Set(CaptureRequest.TonemapMode, (int)TonemapMode.HighQuality);

                mPreviewRequestBuilder.AddTarget(surface);


                // Here, we create a CameraCaptureSession for camera preview.
                var surfaces = new List <Surface>();
                surfaces.Add(surface);
                surfaces.Add(mImageReader.Surface);

                mCameraCaptureSessionCallback = new CameraCaptureSessionCallback(this);

                mCameraDevice.CreateCaptureSession(surfaces, mCameraCaptureSessionCallback, null);
            }
            catch (CameraAccessException e)
            {
                Crashes.TrackError(e);
                e.PrintStackTrace();
            }
        }
        void OnOpened(object sender, CameraDeviceEventArgs e)
        {
            cameraOpenCloseLock.Release();
            cameraDevice = e.Camera;

            try
            {
                //SurfaceTexture texture = mTextureView.SurfaceTexture;
                //SurfaceTexture texture = new SurfaceTexture();
                //if (texture == null)
                //{
                //  throw new IllegalStateException("texture is null");
                //}

                //// We configure the size of default buffer to be the size of camera preview we want.
                //texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);
                //texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
                //texture.FrameAvailable += (sender2, e2) =>
                //{
                //  e2.SurfaceTexture.
                //};

                ////// This is the output Surface we need to start preview.
                //Surface surface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface.
                previewRequestBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                previewRequestBuilder.AddTarget(imageReader.Surface);
                //

                // Here, we create a CameraCaptureSession for camera preview.
                var surfaces = new List <Surface>();
                surfaces.Add(imageReader.Surface);

                if (captureSessionListener != null)
                {
                    captureSessionListener.Configured      -= OnConfigured;
                    captureSessionListener.ConfigureFailed -= OnConfigureFailed;
                }
                captureSessionListener                  = new CameraCaptureSessionCallbackListener(cameraDevice);
                captureSessionListener.Configured      += OnConfigured;
                captureSessionListener.ConfigureFailed += OnConfigureFailed;
                cameraDevice.CreateCaptureSession(surfaces, captureSessionListener, null);
            }
            catch (CameraAccessException ex)
            {
                ex.PrintStackTrace();
            }
        }
예제 #20
0
            public void createpreview()
            {
                //Toast.MakeText(Application.Context, "Iam there", ToastLength.Long).Show();
                SurfaceTexture texture = tview.SurfaceTexture;

                texture.SetDefaultBufferSize(imagedimension.Width, imagedimension.Height);
                Surface surface = new Surface(texture);

                Builder = cameradevice.CreateCaptureRequest(CameraTemplate.Preview);
                Builder.AddTarget(surface);
                outputs.Add(surface);
                cameradevice.CreateCaptureSession(outputs, capturecallback, null);

                //throw new NotImplementedException();
            }
예제 #21
0
        /// <summary>
        ///  Starts preview before recording video.
        /// </summary>
        public void StartPreviewForVideo()
        {
            if (null == mCameraDevice || !mTextureView.IsAvailable || null == mPreviewSize)
            {
                return;
            }

            try
            {
                //wake up the cpu
                PowerManager powerManager = (PowerManager)_context.GetSystemService(Context.PowerService);
                wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "MyApp::MyWakelockTag");
                wakeLock.Acquire();
                SetUpMediaRecorder();
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                //Assert.IsNotNull(texture);
                // texture.SetDefaultBufferSize(CamcorderProfile.Get(CamcorderQuality.High., CamcorderProfile.Get(Height));
                mPreviewRequestBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Record);
                var surfaces       = new List <Surface>();
                var previewSurface = new Surface(texture);
                surfaces.Add(previewSurface);
                mPreviewRequestBuilder.AddTarget(previewSurface);
                var recorderSurface = mediaRecorder.Surface;
                surfaces.Add(recorderSurface);
                mPreviewRequestBuilder.AddTarget(recorderSurface);
                mCameraDevice.CreateCaptureSession(surfaces, new PreviewCaptureStateCallback(this), mBackgroundHandler);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (IOException e)
            {
                e.PrintStackTrace();
            }
        }
        public override void OnOpened(CameraDevice camera)
        {
            System.Diagnostics.Debug.WriteLine("CameraStateListener.OnOpened");

            owner.Camera = camera;
            var surface = owner.Surface;

            List <Surface> list = new List <Surface>
            {
                surface
            };

            owner.PreviewRequestBuilder = camera.CreateCaptureRequest(CameraTemplate.Preview);
            owner.PreviewRequestBuilder.AddTarget(surface);

            camera.CreateCaptureSession(list, new CameraSessionListener(this.owner), null);
        }
예제 #23
0
        public void CreateCameraPreviewSession()
        {
            try
            {
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                if (texture == null)
                {
                    throw new IllegalStateException("texture is null");
                }

                // We configure the size of default buffer to be the size of camera preview we want.
                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                // This is the output Surface we need to start preview.
                Surface surface = new Surface(texture);

                Activity.RunOnUiThread(new Runnable(() =>
                {
                    DisplayMetrics displayMetrics = new DisplayMetrics();
                    Activity.WindowManager.DefaultDisplay.GetMetrics(displayMetrics);
                    int height = displayMetrics.HeightPixels;
                    int width  = displayMetrics.WidthPixels;
                    roi.Left   = 0;
                    roi.Top    = 0;
                    roi.Right  = width;
                    roi.Bottom = height;
                }));
                ChangeScale();
                ChangeRoi();

                // We set up a CaptureRequest.Builder with the output Surface.
                mPreviewRequestBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                mPreviewRequestBuilder.AddTarget(surface);

                // Here, we create a CameraCaptureSession for camera preview.
                List <Surface> surfaces = new List <Surface>();
                surfaces.Add(surface);
                surfaces.Add(mImageReader.Surface);

                mCameraDevice.CreateCaptureSession(surfaces, new CameraCaptureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
예제 #24
0
        public void CreateCaptureSession()
        {
            var surface = mYuvImageReader.Get().Surface;
            //surface.DescribeContents()
            CameraCaptureSessionCallback ccsc =
                new CameraCaptureSessionCallback(mCameraDevice, surface, mCameraStateLock, mBackgroundHandler, TAG);

            ccsc.OnConfigurationComplete += (sender, args) =>
            {
                mState          = STATE_PREVIEW;
                mCaptureSession = args;
            };
            mCameraDevice.CreateCaptureSession(new List <Surface>()
            {
                surface
            }, ccsc, mBackgroundHandler);
        }
예제 #25
0
        private void CreateCaptureSession()
        {
            //SurfaceTexture texture = _textureView.SurfaceTexture; //エラーになる
            //バッファのサイズをプレビューサイズに設定(画面サイズ等適当な値を入れる)
            _surfaceTexture.SetDefaultBufferSize(_previewSize.Width, _previewSize.Height);
            Surface surface = new Surface(_surfaceTexture);

            List <Surface> list = new List <Surface>();

            list.Add(surface);
            list.Add(_recorder.Surface);

            CaptureRequest.Builder captureRequest = _cameraDevice.CreateCaptureRequest(CameraTemplate.Record);
            captureRequest.AddTarget(surface);
            captureRequest.AddTarget(_recorder.Surface);
            _captureRequest = captureRequest.Build();
            _cameraDevice.CreateCaptureSession(list, new CameraCaputureSessionCallBack(_captureRequest), null);
        }
예제 #26
0
            private void OnCameraDeviceOpened(CameraDevice camera)
            {
                try
                {
                    Target = ImageReader.NewInstance(1280, 720, Android.Graphics.ImageFormatType.Jpeg, 2);
                    Target.SetOnImageAvailableListener(new MyImageAvailableCallback(this), null);
                    var outputSurfaces = new List <Surface>()
                    {
                        Target.Surface
                    };

                    camera.CreateCaptureSession(outputSurfaces, new MySessionStateCallback(this), null);
                }
                catch (System.Exception sex)
                {
                    OnError("Failed to create session: " + sex.Message);
                }
            }
        public void CreateCameraPreview()
        {
            SurfaceTexture texture = cameraPreview.SurfaceTexture;

            if (texture == null)
            {
                throw new CameraViewException("Failed to get the surface texture");
            }
            var bufferSize = GetBufferSize(new Vector <int, int>((int)Element.Width, (int)Element.Height));
            //texture.SetDefaultBufferSize(bufferSize.X, bufferSize.Y);
            Surface surface = new Surface(texture);

            CaptureRequestBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            CaptureRequestBuilder.AddTarget(surface);
            CameraDevice.CreateCaptureSession(new System.Collections.Generic.List <Surface>()
            {
                surface
            }, cameraCaptureSessionStateCallback, null);
        }
예제 #28
0
        protected override void CreateCameraCaptureSession()
        {
            try
            {
                CaptureRequestBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                CaptureRequestBuilder.AddTarget(_imageReader.Surface);

                var surfaces = new List <Surface>
                {
                    _imageReader.Surface
                };

                CameraDevice.CreateCaptureSession(surfaces, CameraCaptureSessionStateHandler, null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
예제 #29
0
        public void StartPreview()
        {
            if (CameraDevice == null || !this.IsAvailable || previewSize == null)
            {
                return;
            }

            var texture = this.SurfaceTexture;

            texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
            var surface = new Surface(texture);

            CaptureRequestBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            CaptureRequestBuilder.AddTarget(surface);

            CameraDevice.CreateCaptureSession(new List <Surface> {
                surface
            },
                                              GetYsCameraCaptureSessionStateCallback(),
                                              null);
        }
예제 #30
0
        public void StartPreview()
        {
            if (CameraDevice == null || !_cameraTexture.IsAvailable || _previewSize == null)
            {
                return;
            }

            var texture = _cameraTexture.SurfaceTexture;

            texture.SetDefaultBufferSize(_previewSize.Width, _previewSize.Height);

            var surface = new Surface(texture);

            _previewBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            _previewBuilder.AddTarget(surface);

            System.Diagnostics.Debug.WriteLine("Openning camera preview : " + _previewSize.Width + "x" + _previewSize.Height);

            List <Surface> surfaces = new List <Surface>();

            surfaces.Add(surface);
            surfaces.Add(_imageReader.Surface);

            // Here, we create a CameraCaptureSession for camera preview
            CameraDevice.CreateCaptureSession(surfaces,
                                              new CameraCaptureStateListener
            {
                OnConfigureFailedAction = session =>
                {
                    System.Diagnostics.Debug.WriteLine("Failed.");
                },
                OnConfiguredAction = session =>
                {
                    _previewSession = session;
                    UpdatePreview();
                }
            },
                                              _backgroundHandler);
        }