小编of3*_*inc的帖子

如何根据预览显示上的矩形裁剪 CameraX 捕获的图像

你好,我是android开发新手,谁能帮我根据PreviewView上的矩形裁剪CameraX捕获的图像?

这是activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/frameRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.camera.view.PreviewView
            android:id="@+id/viewFinder"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <View
            android:id="@+id/viewOverlay_center"
            android:background="@drawable/card_rectangle"
            android:layout_width="270dp"
            android:layout_height="400dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/ll_bottom"/>

        <LinearLayout
            android:id="@+id/ll_bottom"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent">

            <ImageView
                android:id="@+id/image_capture_button"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:background="?android:selectableItemBackground"
                android:src="@drawable/shutter_camera" />
        </LinearLayout>
        
    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的MainActivity.java:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(viewBinding.getRoot());

        viewBinding.imageCaptureButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                capturePhoto();
            }
        });
    }

    private void capturePhoto(){
        if (imageCapture == null) …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-camerax

6
推荐指数
1
解决办法
3631
查看次数

标签 统计

android ×1

android-camerax ×1

android-studio ×1