簡體   English   中英

CameraX:如何顯示 16:9 比例預覽?

[英]CameraX : how to display a 16:9 ratio preview?

我目前正在嘗試使用 Android Jetpack 的新 cameraX library 開發 QRCode 掃描儀。 我使用最新的可用版本: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的比例方面:

<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>

預覽看起來不錯:

在此處輸入圖像描述

現在,我已將代碼更新到CameraFragment class 中,以便使用新的AspectRatio枚舉。

所以現在,相機預覽配置如下所示:

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值的實現問題?

預先感謝您的幫助!

問題直接進入圖書館。 最新的 alpha (alpha-08) 不再存在此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM