java - 如何在 AndroidStudio 中使用 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 打开相机视图,我应该怎么做那个矩形?
解决方案
您可以使用相机套件https://github.com/CameraKit/camerakit-android 它使用表面视图,在其中您可以根据需要自定义相机。
<?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" />
推荐阅读
- python - 列表、系列、字典、数据框 - 何时使用哪个以及为什么?
- regex - 我想要在第一行第一次出现的正则表达式
- c - 什么是 u64.l 和 u64.h?
- redux - React Redux Thunk 在 Action Creator 中传递 This.Props 方法
- sql - 具有不同列的 INNER JOIN
- mysql - centos7无法登录phpmyadmin
- java - 使用字符串生成器将 XML 放置在单个 csv/xls 列中不起作用
- javascript - 在 Angular JS 上预先填写关键字搜索过滤器
- jqplot - jqPlot - 绘制面积图和条形图/折线图时颜色的重叠
- sql-server - 如何创建只能访问运行存储过程的登录名?