protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); if (!SetUpCameraOutputs()) { return; } this.mOnYuvImageAvailableListener.OnImageProcessed += (sender, mat) => { SetImage(mat); }; var activity = this; CameraManager manager = (CameraManager)activity.GetSystemService(Context.CameraService); mStateCallback = new CameraStateListener(this); try { Handler backgroundHandler; var list = manager.GetCameraIdList(); var cameraId = list[0]; backgroundHandler = mBackgroundHandler; // Attempt to open the camera. mStateCallback will be called on the background handler's // thread when this succeeds or fails. manager.OpenCamera(cameraId, mStateCallback, backgroundHandler); } catch (CameraAccessException e) { e.PrintStackTrace(); } catch (Java.Lang.InterruptedException e) { throw new Java.Lang.RuntimeException("Interrupted while trying to lock camera opening.", e); } this.OnButtonClick += (sender, args) => { CreateCaptureSession(); }; }
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); }
internal Camera2Controller(PhotoCaptureView photoCaptureView) : base(photoCaptureView) { _captureCallback = new CaptureCallback(this); _stateCallback = new CameraStateCallback(this); _imageAvailableListener = new OnImageAvailableListener(this); _captureStateCallback = new CaptureStateCallback(OnConfigured); }
/// <summary> /// Constructor. /// </summary> /// <param name="activity">Activity.</param> public CameraHelper(Activity activity) { mActivity = activity; mStateCallback = new CameraDeviceStateCallback(this); StartCameraThread(); }