如何在AndroidStudio中使用EasyImage将矩形叠加层添加到相机屏幕上

时间:2018-12-13 14:05:22

标签: java android kotlin easyimage

我有这段代码在用户按下按钮时运行:

    fun takeImage(fragment: Fragment?) {
        Dexter.withActivity(fragment?.activity)
                .withPermissions(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .withListener(object : BaseMultiplePermissionsListener() {
                    override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
                        if (report?.areAllPermissionsGranted() == true)
                            EasyImage.openChooserWithGallery(fragment, fragment?.getString(R.string.select_image), 0)
                        else
                            // Show Error
                    }
                })
                .check()
    }

我希望相机以白色矩形作为占位符打开,以便用户可以将需要拍照的卡放入其中,如下所示: https://i.stack.imgur.com/QurcT.png

我正在使用EasyImage打开相机视图,该怎么做该矩形?

1 个答案:

答案 0 :(得分:0)

您可以使用相机套件https://github.com/CameraKit/camerakit-android 它使用了Surfaceview,可以在其中自定义摄像头。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    android:fitsSystemWindows="true">

    <com.camerakit.CameraKitView
        android:id="@+id/cameraKitView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignTop="@+id/maskView"
        android:layout_alignBottom="@+id/maskView"
        android:adjustViewBounds="true"
        android:keepScreenOn="true"
        app:camera_flash="off"
        app:camera_focus="auto"
        app:camera_permissions="camera" />

    <br.com.getninjas.pro.view.SquareImageView
        android:id="@+id/maskView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mask_camera_toolbar"
        tools:background="@drawable/ic_document_selfie_mask" />

Sample image