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);
        }
Ejemplo n.º 2
0
        public void TakePhoto()
        {
            if (_context == null || CameraDevice == null)
            {
                return;
            }

            if (_captureBuilder == null)
            {
                _captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
            }

            _captureBuilder.AddTarget(_imageReader.Surface);

            _captureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            SetAutoFlash(_captureBuilder);

            _previewSession.StopRepeating();
            _previewSession.Capture(_captureBuilder.Build(),
                                    new CameraCaptureStillPictureSessionCallback
            {
                OnCaptureCompletedAction = session =>
                {
                    UnlockFocus();
                }
            }, null);
        }
Ejemplo n.º 3
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,
                    mImageReader.Surface
                };
                mCameraDevice.CreateCaptureSession(surfaces, new CaptureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
Ejemplo n.º 4
0
        private async Task OpenAsync(bool hasPreview)
        {
            _hasPreview = hasPreview;
            _backgroundThread.Start();
            LockCameraOpening();
            _asyncAutoResetEvent = new AsyncAutoResetEvent(false);
            _manager.OpenCamera(_cameraId, _stateCallback, _backgroundThread.Handler);
            await _asyncAutoResetEvent.WaitAsync(TimeSpan.FromSeconds(3));

            _previewRequestBuilder = _cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
        }
Ejemplo n.º 5
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);
            }
        }
            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)
                {
                    // エラー時の処理を記載
                }
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Capture a still picture. This method should be called when we get a response in
        /// CaptureCallback from both LockFocus()
        /// </summary>
        public void CaptureStillPicture()
        {
            try
            {
                var activity = Activity;
                if (null == activity || null == CameraDevice)
                {
                    return;
                }
                // This is the CaptureRequest.Builder that we use to take a picture.
                CaptureRequest.Builder captureBuilder =
                    CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                captureBuilder.AddTarget(mImageReader.Surface);

                // Use the same AE and AF modes as the preview.
                captureBuilder.Set(CaptureRequest.ControlAfMode,
                                   (int)ControlAFMode.ContinuousPicture);
                SetAutoFlash(captureBuilder);

                // Orientation
                int rotation = (int)activity.WindowManager.DefaultDisplay.Rotation;
                captureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation));

                var captureCallback = new CameraCaptureSessionCaptureCallback2(this);

                CaptureSession.StopRepeating();
                CaptureSession.Capture(captureBuilder.Build(), captureCallback, null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
        // Capture a still picture. This method should be called when we get a response in
        // {@link #mCaptureCallback} from both {@link #lockFocus()}.
        public void CaptureStillPicture()
        {
            try
            {
                var activity = Activity;
                if (null == activity || null == CameraDevice)
                {
                    return;
                }

                // This is the CaptureRequest.Builder that we use to take a picture.
                //if (_stillCaptureBuilder == null)
                //{
                _stillCaptureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                //}

                _stillCaptureBuilder.AddTarget(_imageReader.Surface);

                // Use the same AE and AF modes as the preview.
                _stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
                SetAutoFlash(_stillCaptureBuilder);

                CaptureSession.StopRepeating();
                CaptureSession.Capture(_stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null);
            }
            catch (CameraAccessException ex)
            {
#if DEBUG
                ex.PrintStackTrace();
#endif
            }
        }
Ejemplo n.º 9
0
        public void StartPreview()
        {
            if (CameraDevice == null || !cameraTexture.IsAvailable || previewSize == null)
            {
                return;
            }

            SurfaceTexture texture = cameraTexture.SurfaceTexture;

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

            Surface 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);
        }
Ejemplo n.º 10
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;
            }
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
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());
        }
Ejemplo n.º 15
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 => { }));
        }
Ejemplo n.º 16
0
        public void TakePhoto()
        {
            if (_context == null || CameraDevice == null)
            {
                return;
            }

            if (_captureBuilder == null)
            {
                _captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
            }
            _captureBuilder.AddTarget(_imageReader.Surface);
            _captureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            SetAutoFlash(_captureBuilder);

            var windowManager = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            int rotation      = (int)windowManager.DefaultDisplay.Rotation;
            int orientation   = GetOrientation(rotation);

            _captureBuilder.Set(CaptureRequest.JpegOrientation, orientation);

            _previewSession.StopRepeating();
            _previewSession.AbortCaptures();
            _previewSession.Capture(_captureBuilder.Build(),
                                    new CameraCaptureStillPictureSessionCallback
            {
                OnCaptureCompletedAction = session =>
                {
                    UnlockFocus();
                }
            }, null);
            // Play shutter sound to alert user that image was captured
            var am = (AudioManager)_context.GetSystemService(Context.AudioService);

            if (am != null && am.RingerMode == RingerMode.Normal)
            {
                var cameraSound = new MediaActionSound();
                cameraSound.Load(MediaActionSoundType.ShutterClick);
                cameraSound.Play(MediaActionSoundType.ShutterClick);
            }
        }
Ejemplo n.º 17
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();
            }
        }
Ejemplo n.º 18
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);
                }
            }
        }
Ejemplo n.º 19
0
 private CaptureRequest CreateCaptureRequest()
 {
     try
     {
         CaptureRequest.Builder builder = _cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
         builder.AddTarget(_surface);
         return(builder.Build());
     }
     catch (CameraAccessException e)
     {
         Log.Error(_tag, e.Message);
         return(null);
     }
 }
Ejemplo n.º 20
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();
            }
        }
Ejemplo n.º 21
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);
            }
        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();
            }
        }
Ejemplo n.º 23
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();
            }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 26
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();
            }
        }
Ejemplo n.º 27
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);
        }
        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);
        }
Ejemplo n.º 29
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();
            }
        }
Ejemplo n.º 30
0
        private void OnPreviewSessionConfigured(CameraCaptureSession session)
        {
            captureSession = session;

            previewRequestBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            previewRequestBuilder.AddTarget(previewSurface);

            var availableAutoFocusModes = (int[])characteristics.Get(CameraCharacteristics.ControlAfAvailableModes);

            if (availableAutoFocusModes.Any(afMode => afMode == (int)ControlAFMode.ContinuousPicture))
            {
                previewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            }
            SetAutoFlash(previewRequestBuilder);

            previewRequest = previewRequestBuilder.Build();

            captureSession.SetRepeatingRequest(previewRequest, cameraCaptureCallback, backgroundHandler);
        }