private void SetUpCameraOutputs(int width, int height) { _manager = (CameraManager)_context.GetSystemService(Context.CameraService); string[] cameraIds = _manager.GetCameraIdList(); _cameraId = cameraIds[0]; for (int i = 0; i < cameraIds.Length; i++) { CameraCharacteristics chararc = _manager.GetCameraCharacteristics(cameraIds[i]); var facing = (Integer)chararc.Get(CameraCharacteristics.LensFacing); if (facing != null && facing == (Integer.ValueOf((int)lensFacing))) { continue; } _cameraId = cameraIds[i]; } var characteristics = _manager.GetCameraCharacteristics(_cameraId); var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap); if (_supportedJpegSizes == null && characteristics != null) { _supportedJpegSizes = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.Jpeg); } if (_supportedJpegSizes != null && _supportedJpegSizes.Length > 0) { _idealPhotoSize = GetOptimalSize(_supportedJpegSizes, 1050, 1400); //MAGIC NUMBER WHICH HAS PROVEN TO BE THE BEST } _imageReader = ImageReader.NewInstance(_idealPhotoSize.Width, _idealPhotoSize.Height, ImageFormatType.Jpeg, 1); var readerListener = new ImageAvailableListener(); readerListener.Photo += (sender, buffer) => { Photo?.Invoke(this, buffer); }; var available = (Java.Lang.Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable); if (available == null) { _flashSupported = false; } else { _flashSupported = (bool)available; } _imageReader.SetOnImageAvailableListener(readerListener, _backgroundHandler); _previewSize = GetOptimalSize(map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))), width, height); }
private void SetUpCameraOutputs(int width, int height) { _manager = (CameraManager)_context.GetSystemService(Context.CameraService); string[] cameraIds = _manager.GetCameraIdList(); _cameraId = cameraIds[0]; for (int i = 0; i < cameraIds.Length; i++) { CameraCharacteristics chararc = _manager.GetCameraCharacteristics(cameraIds[i]); var facing = (Integer)chararc.Get(CameraCharacteristics.LensFacing); if (facing != null && facing == Integer.ValueOf((int)lensFacing)) { _cameraId = cameraIds[i]; //Phones like Galaxy S10 have 2 or 3 frontal cameras usually the one with flash is the one //that should be chosen, if not It will select the first one and that can be the fish //eye camera if (HasFLash(chararc)) { break; } } } var characteristics = _manager.GetCameraCharacteristics(_cameraId); var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap); if (_supportedJpegSizes == null && characteristics != null) { _supportedJpegSizes = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.Jpeg); } if (_supportedJpegSizes != null && _supportedJpegSizes.Length > 0) { _idealPhotoSize = GetOptimalSize(_supportedJpegSizes, 1050, 1400); //MAGIC NUMBER WHICH HAS PROVEN TO BE THE BEST } _imageReader = ImageReader.NewInstance(_idealPhotoSize.Width, _idealPhotoSize.Height, ImageFormatType.Jpeg, 1); var readerListener = new ImageAvailableListener(); readerListener.Photo += (sender, buffer) => { Photo?.Invoke(this, buffer); }; _flashSupported = HasFLash(characteristics); _imageReader.SetOnImageAvailableListener(readerListener, _backgroundHandler); _previewSize = GetOptimalSize(map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))), width, height); }