简体   繁体   English

使用 CameraX 使用长焦镜头进行变焦

[英]Zoom with the telephoto lens with CameraX

In my app, zooming is limited to the main lens instead of the telephoto lens of the device(if there is one).在我的应用程序中,变焦仅限于主镜头,而不是设备的长焦镜头(如果有的话)。

The telephoto lens could be provided by any manufacturer;长焦镜头可以由任何制造商提供; I do not wish to implement an API specific to a manufacturer's device to access the telephoto or wide angle lens.我不希望实现特定于制造商设备的 API 来访问长焦或广角镜头。

This results in less optimal pictures, and the app cannot zoom further then the main camera's zoom limits.这会导致不太理想的图片,并且应用程序无法进一步缩放到主摄像头的缩放限制。

How do I use the telephoto lens (and wide angle lens as well if possible) to zoom in my app?如何使用长焦镜头(如果可能,也可以使用广角镜头)放大我的应用程序?

Thanks.谢谢。

CameraX is simply not capable of giving you the camera/lens you wish/need. CameraX 根本无法为您提供您想要/需要的相机/镜头。 You can set the zoom level to minimum available and hope for the best.您可以将缩放级别设置为最低可用,并希望获得最好的结果。 You can try Camera2 but it is also not guaranteed.您可以尝试 Camera2,但也不能保证。
In theory, If you set zoom ratio to something below 1.0f, this should make cameraX to use wide angle camera.理论上,如果您将缩放比例设置为低于 1.0f,这应该会使 cameraX 使用广角相机。 In reality, I have never seen any device apart from Pixel 6 supporting this.实际上,除了 Pixel 6 之外,我从未见过任何设备支持此功能。 Even Google Pixel are not capable of implementing necessary features to support 3rd party camera apps with CameraX.甚至 Google Pixel 也无法实现必要的功能来支持带有 CameraX 的 3rd 方相机应用程序。 In case you want to check, this is how you can set minimum available zoom: In most devices you will see minimum zoom is 1.0f while in Pixel 6 it was ~0.7f.如果您想检查,可以通过以下方式设置最小可用缩放:在大多数设备中,您会看到最小缩放为 1.0f,而在 Pixel 6 中为 ~0.7f。

val maxAvailableZoom = camera?.cameraInfo?.zoomState?.value?.maxZoomRatio
val minAvailableZoom = camera?.cameraInfo?.zoomState?.value?.minZoomRatio ?: 1f
camera?.cameraControl?.setZoomRatio(minAvailableZoom)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM