为 CameraX 设置目标分辨率不像文档中那样工作

Setting target resolution for CameraX not working as in documentation

我想使用 CameraX 库以固定分辨率(即 1200x1600)拍摄照片。

所以根据文档我可以为 ImageCaptureConfig:

设置目标分辨率
val imageCaptureConfig = ImageCaptureConfig.Builder()
    .setLensFacing(CameraX.LensFacing.BACK)
    .setCaptureMode(ImageCapture.CaptureMode.MAX_QUALITY)
    .setTargetResolution(Size(1200, 1600))
    .setTargetAspectRatio(Rational(3,4))
    .build()

文档描述 setTargetResolution 方法如下:

Sets the intended output target resolution.

The target resolution attempts to establish a minimum bound for the image resolution. The actual image resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen.

如果我错了请纠正我,但如果设备能够拍摄大于 1200x1600 的照片(例如 3024x4032),输出照片将至少为 1200x1600

不幸的是,在许多设备中(例如 Huawei P20 ProSamsung A5)输出的照片明显小于 1200x1600,例如480x640。请注意,这些设备能够拍摄非常大的照片。

是我的 ImageCaptureConfig 配置不当还是这是一个错误?

这可能是 AOSP 最近修复的错误。 参考 https://android.googlesource.com/platform/frameworks/support/+/5c1aed8c4c502a74eb4ee6d30fe2089f4afcaf11

android documentation这样说:

You cannot set both target aspect ratio and target resolution on the same use case. Doing so will throw an IllegalArgumentException when building the config object.

所以决定什么对你来说更重要,只选择一个。