我正在尝试创建一个垂直模式的预览,并希望预览的宽度与屏幕一样,并在垂直方向上包裹内容。然而,当我这样做时,我总是得到预览大小为 1200x1200
,并且预览被水平拉伸以填充屏幕。
但是捕获的图像大小是正确的(1024x768
)。
换句话说,我希望预览大小与捕获的图像大小相同。
任何帮助都将不胜感激。
preview = new Preview.Builder()
.setTargetAspectRatioCustom(new Rational(3, 4))
.build();
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.molescope.CameraXActivity">
<androidx.camera.view.PreviewView
android:id="@+id/preview_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageButton
android:id="@+id/capture_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="@dimen/margin_vertical"/>
</androidx.constraintlayout.widget.ConstraintLayout>
def camerax_version = "1.0.0-beta03"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha10"
implementation "androidx.camera:camera-extensions:1.0.0-alpha10"