当前位置: 首页 > 知识库问答 >
问题:

如何为android ZBar QrCode阅读器定制CameraView

干亮
2023-03-14

我正在使用Zbar阅读QRcode。我将这个https://github.com/dushyanthmaguluru/zbarscanner示例用于我的activity。问题是我如何在我的框架图上显示cameraView?

编辑:

        @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    mCamera = getCameraInstance();

    if(!isCameraAvailable())
    {
        cancelRequest();
        return;
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mAutoFocusHandler = new Handler();

    setupScanner();

    mPreview = new CameraPreview(this, this, autoFocusCB);
    //setContentView(mPreview);
    FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview);
    preview.addView(mPreview);
}

null

null

共有1个答案

孙元明
2023-03-14

首先,删除在我看来获得相机访问权的行:mcamera=getCameraInstance();。您不想这样做,因为camerapreview会为您这样做。

我不会使用框架图,因为项目是一个接一个的,你想把你的相机审查最后。所以您应该在另一个relativeLayout中有一个linearlayout(我知道,它效率不高,但现在还可以)。类似于(main.xml布局):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/zbar_layout_area"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <ImageView
        android:id="@+id/my_own_image_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/my_own_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

现在,您需要将CameraPreview放入zbar_layout_area中。为此,尝试将代码改为(盲编码):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!isCameraAvailable()) {
        // Cancel request if there is no rear-facing camera.
        cancelRequest();
        return;
    }

    // Hide the window title.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

    mAutoFocusHandler = new Handler();

    // Create and configure the ImageScanner;
    setupScanner();

    // Create a RelativeLayout container that will hold a SurfaceView,
    // and set it as the content of our activity.
    mPreview = new CameraPreview(this, this, autoFocusCB);
    LinearLayout zbarLayout = (LinearLayout) findViewById(R.id.zbar_layout_area);
    mPreview.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    zbarLayout.addView(mPreview);
}

还要确保设置了足够的特权:

<uses-permission android:name="android.permission.CAMERA" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
 类似资料:
  • 问题内容: 我有以下从缓冲读取器读取数据的示例: 每当缓冲读取器中出现某些情况时(在这种情况下),将执行循环中的代码。在我的情况下,如果客户端应用程序将某些内容写入套接字,则将执行循环中的代码(服务器应用程序中)。 但是我不明白它是如何工作的。等待直到缓冲读取器中出现某些内容,当其中出现某些内容时,它将返回并执行循环中的代码。但是什么时候可以退货。 还有另一个问题。上面的代码摘自一个方法,我在线程

  • 欢迎来到Go的世界,让我们开始探索吧! Go是一种新的语言,一种并发的、带垃圾回收的、快速编译的语言。它具有以下特点: 它可以在一台计算机上用几秒钟的时间编译一个大型的Go程序。 Go为软件构造提供了一种模型,它使依赖分析更加容易,且避免了大部分C风格include文件与库的开头。 Go是静态类型的语言,它的类型系统没有层级。因此用户不需要在定义类型之间的关系上花费时间,这样感觉起来比典型的面向对

  • 问题内容: 堆栈: Java-1.8.0_91 Scala-2.11.8 库-it.geosolutions.imageio-ext imageio-ext-tiff 1.1.15 我们正在读取许多旧的TIF图像,并且由于某种原因读取的数据高度不一致-出于某些原因,在不同的运行中读取同一图像可能会成功或失败,但是- 代码是这样的: 问题是ImageIO同时初始化2个TIFF读取器 要么 第一个失败

  • 你好,我正在尝试使用火花从文本文件中读取特定的行。 它可以用。获取第一行数据的第一个()命令。文本文件。如何访问文档的第n行?我需要java解决方案。

  • 我试图在Java中使用GZIPInputStream来解压缩来自我的。NET应用程序(它以GZIP格式压缩)的图像数据。图像数据以Base64字符串传输,因为它是作为XML文本同步的。我假设流会读取到传入. read()参数的缓冲区中,直到缓冲区饱和。它没有像我预期的那样工作,也就是说,. read()每次读取操作只能读取800字节左右。这对于小图像不是问题,但对于大图像,如800 KB,解压缩需

  • 在问题[1]中,我了解到如果您想在Android下使用NFC标签,则不必采用NDEF格式。我想在Win 8.1 in. Net下执行此操作。我的情况是这样的: 我有一个RFID卡Mifare Classic 1K,其中存储了一个ID。(由制造商记录)该ID由我们的考勤系统通过通常的RFID读取器(例如Gigatek的PROMAG MFR120)读取。我们不在卡上写任何东西,我们只需要读取ID。但是