Android的CameraX获得相机支持分辨率的方法
如题,方法如下:
androidx.camera.core.Camera camera1 = cameraProvider.bindToLifecycle(/* lifecycleOwner= */ this, cameraSelector, analysisUseCase); Camera2CameraInfo camera2Info = Camera2CameraInfo.from(camera1.getCameraInfo()); Size[] size = camera2Info.getCameraCharacteristic(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputSizes(ImageFormat.JPEG); logger.info("Get size");
Size的数组即为支持的分辨率,设置分辨率的方法如下:
ImageAnalysis.Builder builder = new ImageAnalysis.Builder(); ResolutionSelector.Builder resolutionBuilder = new ResolutionSelector.Builder(); builder.setResolutionSelector(resolutionBuilder.setResolutionStrategy(new ResolutionStrategy(new Size(1920, 1080), ResolutionStrategy.FALLBACK_RULE_NONE)).build()); analysisUseCase = builder.build();
Preview的时候:
Preview.Builder builder = new Preview.Builder(); ResolutionSelector.Builder resolutionBuilder = new ResolutionSelector.Builder(); builder.setResolutionSelector(resolutionBuilder.setResolutionStrategy(new ResolutionStrategy(new Size(1920, 1080), ResolutionStrategy.FALLBACK_RULE_NONE)).build()); //builder.setResolutionSelector(resolutionBuilder.setResolutionStrategy(ResolutionStrategy.HIGHEST_AVAILABLE_STRATEGY).build()); previewUseCase = builder.build();
Written By BlueZealot