首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CameraX :如何显示16:9的比例预览?

CameraX :如何显示16:9的比例预览?
EN

Stack Overflow用户
提问于 2019-10-25 16:41:02
回答 1查看 885关注 0票数 2

我目前正在尝试开发一个QRCode扫描仪与新的cameraX livrary从Android Jetpack。我使用可用的最新版本: 1.0.0-alpha06

在CameraXBasic示例(https://github.com/android/camera-samples/tree/master/CameraXBasic)中,在将cameraX库版本从1.0.0-alpha05更新到1.0.0-alpha06之后,我尝试显示16:9的比例预览,而不是全屏预览。

为了做到这一点,我更新了fragment_camera.xml布局,以便“强制”TextureView的比率方面:

代码语言:javascript
复制
<androidx.constraintlayout.widget.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/camera_container"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/black"
  >
    <TextureView
      android:id="@+id/view_finder"
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintDimensionRatio="16:9"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      />
</androidx.constraintlayout.widget.ConstraintLayout>

预览效果很好:

现在,为了使用新的AspectRatio枚举,我已经将代码更新到CameraFragment类中。

因此,现在,摄像机预览配置如下:

代码语言:javascript
复制
val viewFinderConfig = PreviewConfig.Builder().apply {
  setLensFacing(lensFacing)
  // We request aspect ratio but no resolution to let CameraX optimize our use cases
  setTargetAspectRatio(AspectRatio.RATIO_16_9)
  // 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()

不幸的是,结果看起来是1:1的比例,而不是16:9:

如果我使用AspectRatio.RATIO_4_3值而不是AspectRatio.RATIO_16_9,结果看起来很好:

是库有问题,还是使用AspectRatio.RATIO_16_9值的实现有问题?

提前感谢您的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-23 17:24:21

问题是直接在库中出现的。最新的alpha (alpha-08)不再有这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58555058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档