Exemplo n.º 1
0
        public void OpenCamera2(SurfaceTexture surfaceTexture)
        {
            //Camera2
            CameraManager manager = (CameraManager)Android.App.Application.Context.GetSystemService(Context.CameraService);
            //string cameraId = manager.GetCameraIdList().Where(r => manager.GetCameraCharacteristics(r).Get(CameraCharacteristics.LensFacing).ToString() == "").FirstOrDefault();
            string cameraId = manager.GetCameraIdList().FirstOrDefault();
            CameraCharacteristics cameraCharacteristics = manager.GetCameraCharacteristics(cameraId);

            Android.Hardware.Camera2.Params.StreamConfigurationMap scm = (Android.Hardware.Camera2.Params.StreamConfigurationMap)cameraCharacteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
            var previewSize = scm.GetOutputSizes((int)ImageFormatType.Jpeg)[0];

            manager.OpenCamera(cameraId, new CameraCallBack(_recorder, surfaceTexture, previewSize), null);
        }
Exemplo n.º 2
0
        public void StartCamera()
        {
            //アプリ起動時に,表示領域が未作成の前にStartCameraが実行されることを防ぐ
            if (this.SurfaceTexture == null)
            {
                return;
            }

            StartBackgroundThread();

            this._cameraManager = (CameraManager)Android.App.Application.Context.GetSystemService(Context.CameraService);

            var cameraIdList = this._cameraManager.GetCameraIdList();
            CameraCharacteristics cameraCharacteristics = null;

            //指定のカメラのidを取得する
            //フロント,バックのカメラidの取得についてはこちらを参考
            //https://bellsoft.jp/blog/system/detail_538
            this._cameraId = cameraIdList.FirstOrDefault(cId =>
            {
                cameraCharacteristics = _cameraManager.GetCameraCharacteristics(cId);
                var lensFacing        = (int)cameraCharacteristics.Get(CameraCharacteristics.LensFacing);
                if (lensFacing == (int)this.CameraOption)
                {
                    return(true);
                }
                return(false);
            });
            Android.Hardware.Camera2.Params.StreamConfigurationMap scm = (Android.Hardware.Camera2.Params.StreamConfigurationMap)cameraCharacteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
            this.PreviewSize = scm.GetOutputSizes((int)ImageFormatType.Jpeg)[0];

            this.SensorOrientation = (int)cameraCharacteristics.Get(CameraCharacteristics.SensorOrientation);//Back:4032*3024,Front:3264*2448

            //ImageReaderの設定
            this.ImageReader = ImageReader.NewInstance(480, 640, ImageFormatType.Jpeg, 1);
            this.ImageReader.SetOnImageAvailableListener(this.ImageAvailableListener, this.BackgroundHandler);

            this._cameraStateListener = new CameraStateListener(this);

            _cameraManager.OpenCamera(_cameraId, this._cameraStateListener, null);
        }