小编Amr*_*rit的帖子

如何在cameraX预览上设置预览尺寸?

我正在尝试以纵向模式创建预览,并且希望预览与屏幕一样宽并垂直环绕内容。但是,当我这样做时,我总是会获得预览尺寸1200x 1200,并且预览会水平拉伸以填充屏幕。

捕获的图像尺寸正确(1024x768.

换句话说,我希望预览尺寸与捕获的图像相同。

任何帮助将不胜感激。

preview = new Preview.Builder()
            .setTargetAspectRatioCustom(new Rational(3, 4))
            .build();
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
    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"
Run Code Online (Sandbox Code Playgroud)

android android-camerax

7
推荐指数
1
解决办法
2万
查看次数

如何在 Android 中冻结 CameraX 预览?

我希望相机在按下图像捕获按钮时冻结预览。我看过其他堆栈溢出问题,但它们已经过时了。

我使用的cameraX版本:1.0.0-beta03

任何帮助将不胜感激。谢谢

android android-camerax

0
推荐指数
1
解决办法
3245
查看次数

标签 统计

android ×2

android-camerax ×2