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); }
public static bool IsFlashSupported(Android.Hardware.Camera2.CameraManager cameraManager, string cameraId) { var characteristics = cameraManager.GetCameraCharacteristics(cameraId); // Check if the flash is supported. var available = (Boolean)characteristics.Get(CameraCharacteristics.FlashInfoAvailable); if (available == null) { return(false); } return((bool)available); }
private Android.Util.Size GetBufferSize(Android.Util.Size requestSize) { var characteristics = _manager.GetCameraCharacteristics(_camera.Id); var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap); // ReSharper disable once CoVariantArrayConversion var largest = (Android.Util.Size)Collections.Max( Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Yuv420888)), new CompareSizesByArea()); var swappedDimensions = IsSwappedDimensions(characteristics); var rotatedPreviewSize = GetRotatedPreviewSize(requestSize, swappedDimensions); var maxPreviewSize = GetMaxPreviewSize(swappedDimensions); return(ChooseOptimalSize(map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture))), rotatedPreviewSize.Width, rotatedPreviewSize.Height, maxPreviewSize.Width, maxPreviewSize.Height, largest)); }