简体   繁体   English

如何创建条码扫描器(Android)?

[英]How to create barcode scanner (Android)?

Can someone tell me if creating barcode scanner app (for Android) is difficult? 有人能告诉我是否难以创建条形码扫描器应用程序(适用于Android)? Is OpenCV library good start? OpenCV库是一个良好的开端吗? Where can I find algorithm which clearly explains how to read barcodes? 我在哪里可以找到清楚解释如何读取条形码的算法? I will appreciate all good materials about this topic! 我会很感激有关这个主题的所有好材料!

Thanks in advance! 提前致谢!

The ZXing project provides a standalone barcode reader application which — via Android's intent mechanism — can be called by other applications who wish to integrate barcode scanning. ZXing项目提供了一个独立的条形码阅读器应用程序 - 通过Android的意图机制 - 可以被其他希望集成条形码扫描的应用程序调用。

The easiest way to do this is to call the ZXing SCAN Intent from your application, like this: 最简单的方法是从您的应用程序中调用ZXing SCAN Intent,如下所示:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

Pressing the button linked to mScan would launch directly into the ZXing barcode scanner screen (or crash if ZXing isn't installed). 按下链接到mScan的按钮将直接启动到ZXing条形码扫描仪屏幕(如果未安装ZXing,则会崩溃)。 Once a barcode has been recognised, you'll receive the result in your Activity, here in the contents variable. 一旦识别出条形码,您将在您的活动中收到结果,此处在内容变量中。

To avoid the crashing and simplify things for you, ZXing have provided a utility class which you could integrate into your application to make the installation of ZXing smoother, by redirecting the user to the Android Market if they don't have it installed already. 为了避免崩溃并简化您的工作,ZXing 提供了一个实用程序类 ,您可以将其集成到您的应用程序中,通过将用户重定向到Android Market(如果他们尚未安装),可以使ZXing的安装更加顺畅。

Finally, if you want to integrate barcode scanning directly into your application without relying on having the separate ZXing application installed, well then it's an open source project and you can do so! 最后,如果您想要将条形码扫描直接集成到您的应用程序中而不依赖于安装单独的ZXing应用程序,那么它就是一个开源项目,您可以这样做! :) :)

You can use the existing Zebra Crossing barcode scanner for Android, available at: http://code.google.com/p/zxing/ . 您可以使用适用于Android的现有Zebra Crossing条形码扫描仪, 网址为: http//code.google.com/p/zxing/ Typically the idea is that you would invoke it via intents, like in the example here: http://code.google.com/p/zxing/wiki/ScanningViaIntent . 通常,您可以通过意图调用它,例如: http//code.google.com/p/zxing/wiki/ScanningViaIntent

Zebra Crossing is the best documented java 1D or 2D barcode decoder or encoder around. Zebra Crossing是最好的java 1D或2D条形码解码器或编码器。 Lots of people use it, and it's become the de facto standard for android. 很多人使用它,它已经成为android的事实上的标准。 There's a healthy buzz about it on here too. 这里也有一个健康的嗡嗡声

RedLaser has an api , but you'll have to pay if you use it in production. RedLaser 有api ,但如果你在生产中使用它,你将不得不支付。 When I tried it out, I didn't find it to be a spectacular improvement over Zebra Crossing. 当我试用它时,我发现它并不比Zebra Crossing有了惊人的改进。 Certainly not for the price . 当然不是为了价格

jjil does barcodes but there are only 3 committers on the project, and I've never used it myself so I don't know what to tell you about it. jjil 做条形码,但项目中只有3个提交者,我自己从未使用它,所以我不知道该告诉你什么。 Its source is certainly readable. 它的来源肯定是可读的。

Once you start reading , you'll find readers are tricky things to implement due to blurry images, noise, distortion, weird angles, and so forth. 一旦你开始阅读 ,你会发现由于图像模糊,噪音,失真,奇怪的角度等等,读者都很难实现。 So if you want something reliable, you probably want to go with a community-maintained library. 因此,如果您想要可靠的东西,您可能希望使用社区维护的库。

You can use zbar library. 您可以使用zbar库。 Download it from: http://sourceforge.net/projects/zbar/files/AndroidSDK/ 从以下网址下载: http//sourceforge.net/projects/zbar/files/AndroidSDK/

I think this is more fast and accurate than zxing. 我认为这比zxing更快更准确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM