通过surfaceview使用zxing条码阅读器

2024-03-13

我正在创建一个扫码机应用程序,我想使用Zxing要读取条形码,我的应用程序有一个表面视图并向其中显示相机,但现在我想从 SurfaceView 相机扫描条形码,我使用它的原因是我的布局中的表面视图下有两个 Edittexts 来显示条形码的内容。

我应该如何创建一个像这样的应用程序,主要问题是如何将 zxing 设置到 Surface 中。
如果有什么办法我将不胜感激。

布局截图:


定制您的zxing使用以下代码进行布局。

我在这里拍了一张RelativeLayout用于 zxing 扫描仪。

Or, 参考这个参考文献:

  • https://github.com/dm77/barcodescanner/issues/67 https://github.com/dm77/barcodescanner/issues/67

我的设计如下图所示,如果需要的话可以拍FrameLayout.

XML代码:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">




<android.support.v7.widget.Toolbar
    android:id="@+id/toolbarAdjustScan"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/colorPrimary"
    android:elevation="6dp"
    android:minHeight="56dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/titleToolbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:ellipsize="end"
            android:layout_weight="1"
            android:maxLines="1"
            android:textColor="@color/white"
            android:textSize="18dp" />

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:padding="10dp"
            android:id="@+id/searchAdjustBtn"
            android:layout_marginLeft="15dp"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="SEARCH   "
            android:textColor="@color/white"
            android:textSize="13dp" />
    </LinearLayout>

</android.support.v7.widget.Toolbar>


 <TextView
    android:id="@+id/textv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:gravity="center_horizontal"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:text="Point at any barcode to scan"
    android:textColor="@color/white"
    android:textSize="14sp"
    android:textStyle="normal" />

<RelativeLayout
    android:layout_marginBottom="120dp"
    android:layout_below="@+id/textv"
    android:id="@+id/relative_scan_take_single"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</RelativeLayout>
</LinearLayout>

<LinearLayout
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:background="@color/colorPrimaryDark"
    android:layout_height="120dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/doneBtn"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_gravity="bottom"
        android:text="Done"
        android:textAllCaps="true"
        android:textColor="@color/white"
        android:textSize="22dp" />


</LinearLayout>

活动代码:(Java)

   public class TakeSingleScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;



 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_single_scan);

 //Scanner
        mScannerView = new ZXingScannerView(this);
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.relative_scan_take_single);
        rl.addView(mScannerView);
        mScannerView.setResultHandler(this);
        mScannerView.startCamera();
        mScannerView.setSoundEffectsEnabled(true);
        mScannerView.setAutoFocus(true);

    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过surfaceview使用zxing条码阅读器 的相关文章

随机推荐

  • PostAuthenticateRequest 多次触发

    我有 Forms 身份验证 需要将自定义对象存储在 HttpContext Current User 和 Thread CurrentPrincipal 中 为此 我监听 PostAuthenticateRequest 事件 然后从数据库读
  • 如何将内存流从我的应用程序传递到 DLL 或从 DLL 检索内存流?

    假设我有一个TMemoryStream我需要传递到我的 DLL 并返回TMemoryStream 位图流 来自 DLL 我想我的 DLL 会有 procedure Process InBuff Pointer InBuffSize Inte
  • 实心画笔属性不绑定

    我有一个 X 类 有一些数据 private string yyy public string YYY get return yyy set yyy value NotifyPropertyChanged YYY private Solid
  • 如何确定平移手势的真实结束速度?

    使用时UIPanGestureRecognizer并检测UIGestureRecognizerStateEnded 那么手势的速度就不是真实的速度 相反 它是先前调用我的操作方法的旧速度 如何获取手势结束时的真实速度 我创建我的UIPanG
  • 无需编译即可检查变量实现接口

    我想知道具体类型是否实现特定接口并将其打印出来 我编写了一个示例 0 其中包含自定义结构 MyPoint 而不是接口类型 MyPoint 具有 io Reader 接口中定义的 Read 函数 type MyPoint struct X Y
  • 找到删除分支的人?

    我需要找到在正在合作的项目中删除分支的人 通过检查 repo 文件夹 文件 git refs heads 我找不到包含该信息的任何元数据 找到这个 他有什么办法 您可以在组织仪表板的活动部分下查看此详细信息 只有组织所有者有权访问此页面 h
  • 如何在 Android Studio 中忽略库的 minSdkVersion?

    在我的项目中 minSdkVersion 10 在库中是 11 I get BUILD FAILED Manifest merger failed uses sdk minSdkVersion 10 cannot be smaller th
  • Angular UI 路由器忽略 HTML5 模式关闭

    Angular UI Router 忽略 HTML5Mode false 并且它以无法添加书签或直接登陆的方式呈现链接 app js stateProvider state search url search views main wrap
  • 在 Fortran 中写入现有文件而不覆盖

    我有一个由 Fortran 程序编写的现有文件 已格式化 我想在文件开头添加几行 我们的想法是在不复制原始文件的情况下完成此操作 我可以在文件末尾添加一行 open 21 file myfile dat status old action
  • 从 Java 7 升级到 Java 8 后签名引用失败

    我最近已将 Java 从 7 升级到 8 并且我面临使用 saml 请求的服务之一的问题 我收到以下错误 Jan 05 2015 3 42 06 PM org jcp xml dsig internal dom DOMReference v
  • 在项目的根目录下创建 .env 文件

    我正在尝试从 github 下载一个 Django 项目 其中一个要求是 由于该项目使用 python de Couple 因此您需要在项目的根目录上创建一个名为 env 的文件 其中包含三个值 如下所示 DEBUG True SECRET
  • 将单词 (.docx) 转换为 docbook

    我的任务是找到一种将大量 docx 文件转换为 docbook 5 的方法 目前 我们在 openoffice 中打开该文件并保存到 docbook 这是一项耗时的任务 但我相信有更好的方法 然后 这些文件将被进一步处理为我们的自定义rel
  • 如何在 CMake 中删除字符串中的一行文本,解决 CMake 缺乏基于行的正则表达式匹配的问题?

    我发现 CMake 并没有按照我预期的方式执行 RegEx 显然 其他人也遇到了同样的问题 https cmake org pipermail cmake 2007 October 017107 html问题是 CMake 不是基于行的 当
  • Pip无法安装枕头

    当尝试使用 pip 安装枕头时 会产生此错误 我尝试过重新安装安装工具 但没有效果 我在安装了 Diet Pi 的 pi 0 上运行 pip install pillow Looking in indexes https pypi org
  • Objective-C 中的文本解析?

    是否有任何库可以在 Objective C iPhone 应用程序中解析 Textile Textile 到 HTML C 库也可以工作 Update 我在 C Obj C 中找不到任何足够开发的库 但我确实找到了一个用 Javascrip
  • 多态性、泛型和匿名类型 C#

    考虑以下场景 文档 gt 部分 gt 正文 gt 项目 文档有部分 部分包含正文 正文有一些文本和项目列表 这些项目就是问题的内容 有时项目是基本的字符串列表 但有时项目包含自定义数据类型的列表 So public class Docume
  • 为什么 git Remote prune origin 会删除我的本地标签?

    我有几个标记引用来自本地分支和远程跟踪分支的提交 或这些提交的祖先 我想删除对分支和标签的引用origin跑完后git fetch git remote prune origin dry run 但输出表明它会修剪我的本地标签 即使是我手动
  • YDN DB 包含问题

    我已经包含了 YDN DB 文件 ydn db isw core crypt qry dev js 来加密角度应用程序中的索引数据库 它被添加到 socket io 1 4 5 js 之后的 index html 主体部分中 加载器 spi
  • 从 saber API 发出票据

    我们已经成功实施了 sabre 低价搜索和预订工作流程并创建了 PNR 现在 我想使用 api 开具该 PNR 的机票 My workflow is 1 BargainFinderMaxRQ find 2 EnhancedAirBook b
  • 通过surfaceview使用zxing条码阅读器

    我正在创建一个扫码机应用程序 我想使用Zxing要读取条形码 我的应用程序有一个表面视图并向其中显示相机 但现在我想从 SurfaceView 相机扫描条形码 我使用它的原因是我的布局中的表面视图下有两个 Edittexts 来显示条形码的