我想获得最佳的正方形长宽比质量,并为CameraX设置下一个预览和捕获配置。
val SQUARE_ASPECT_RATIO = Rational(1, 1)
val previewConfig = PreviewConfig.Builder().apply {
setTargetAspectRatio(SQUARE_ASPECT_RATIO)
setTargetRotation(viewFinder.display.rotation)
}.build()
preview = Preview(previewConfig)
val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
setCaptureMode(ImageCapture.CaptureMode.MAX_QUALITY)
setTargetAspectRatio(SQUARE_ASPECT_RATIO)
setTargetRotation(viewFinder.display.rotation)
}.build()
imageCapture = ImageCapture(imageCaptureConfig)
CameraX.bindToLifecycle(this, preview, imageCapture)
CameraX选择352x288px分辨率,因此结果图像分辨率等于288x288px。 根据文档,它应该是当前设备可用的最高分辨率,但不是。
在模拟器和Google Pixel 3上进行了测试。