如何为条形码扫描仪设置框架?

时间:2018-05-16 20:48:26

标签: android android-camera qr-code barcode-scanner

我有一个条形码扫描仪应用程序使用(使用Google Mobile Vision API进行条形码检测) 在相机活动中我想设置一个框架,以便应用程序只读取该框架中的条形码或QR码(就像所有扫描仪应用程序一样) 我该如何定制呢?

这是相机xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".ScanBarcodeActivity">

    <SurfaceView
        android:id="@+id/cammeraPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

这是条形码扫描仪,而不是通用的相机预览不会改变太多。您可以按照此answer在预览曲面上方添加一个矩形。请注意,这意味着您的Activity的顶级布局是FrameLayout。

您可以尝试检查已识别条形码的坐标,如果它们与您绘制的矩形不匹配则忽略它,但IMO这将浪费时间 - 无论是对您还是最终用户。这不会增加识别的可靠性。

另一方面,视觉指南(您的自定义框架)确实改进了条形码扫描器UX,即使它背后没有编程逻辑。