【发布时间】:2020-02-01 15:43:21
【问题描述】:
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之外还有什么解决方法吗?
谢谢!
【问题讨论】:
-
如camerax文档中提到的,它仍处于开发阶段,要么等到它修复或使用camera2 api。
-
S7和S8都有12MP后置摄像头,4032*3024;为什么你写的最大输出分辨率是 3264*2448?
-
@AlexCohn 我正在使用前置摄像头。
标签: android android-camera android-camerax