val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
setLensFacing(CameraX.LensFacing.FRONT)
setCaptureMode(CaptureMode.MAX_QUALITY)
setBufferFormat(ImageFormat.YUV_420_888)
setTargetResolution(Size(3264, 2448))
// We request aspect ratio but no resolution to match preview config but letting
// CameraX optimize for whatever specific resolution best fits requested capture mode
setTargetAspectRatio(Rational(3,4))
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}.build()
imageCapture.takePicture(object : ImageCapture.OnImageCapturedListener() {
override fun onCaptureSuccess(image: ImageProxy?, rotationDegrees: Int) {
println("captureSuccess h: ${image?.height} w: ${image?.width}")
}
override fun onError(imageCaptureError: ImageCapture.ImageCaptureError, message: String, cause: Throwable?) {
println(message)
}
})
以上是我为从三星 S8 美国版捕获图像设置的代码,我想要最大输出分辨率为 3264*2448 的 YUV 格式。但是,我得到的结果是 1440*1080 。我试过 S9 和 S8 亚洲版,代码在两部手机上都可以正常工作。奇怪的是,当我将格式设置为 JPEG 时,它可以在这款手机上使用。
我也尝试过 S7 和像素 2,像素 2 可以以最大支持的分辨率输出 YUV(不是上面的代码),但 S7 不能,也给了我 1080*1440。
这是一个 CameraX 错误吗?如果是,除了使用回到Camera2之外还有其他解决方法吗?
谢谢!