ZXing(1)Barcode Image Library

ZXing(斑马穿越)是一款用于解码和编码条形码的库,包括核心图像解码库及多个客户端应用如Android版条码扫描器等。本文介绍如何准备和使用ZXing代码,涵盖下载、解压、构建过程,并导入Eclipse进行研究。
ZXing(1)Barcode Image Library

1. Overview
ZXing(Zebra Crossing) is design to decode and encode barcode.

The consist of the library
core - The core image decoding library, and test code
Javase
Zxing.org
Android - Android client, called Barcode Scanner
Android-test
Android-integration - Support integration with our Barcode Scanner app via intern

Some other additional modules:
Cpp
IPhone - IPhone client + port to Objective C/C++
Zxing.appspot.com: The source behind our web-based barcode generator
CSharp
JRuby: Ruby wrapper
ActionScript

2. Prepare the codes
Download the latest version of file ZXing-2.1.zip and ZXing-2.1-testdata.zip.
Unzip the project ZXing-2.1.zip first, it contains everything and built by ANT.

The latest version, there are also MAVEN there.
>cd core
>ant
comments the sign part in pom.xml
>mvn clean install -DskipTests=true
>mvn eclipse:eclipse
Import the core part to eclipse to study.

>cd javase
>ant
>mvn eclipse:eclipse

I import this 2 projects in my eclipse and try to understand how it works.

The class I should begin with is
>cd ..
>java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner [URL | FILE]

Some important codes are as follow:
CommandLineRunner.java
CommandLineEncoder.java
DecodeThread.java
GenericMultipleBarcodeReader.java

2. Import the Android Code
Import Android project with exists codes
import the project android and it names CaptureActivity


References:
http://code.google.com/p/zxing/
http://code.google.com/p/zxing/w/list

http://www.cnblogs.com/liuan/archive/2012/01/05/2312714.html
http://www.cnblogs.com/liuan/archive/2012/01/05/2313488.html
http://www.cnblogs.com/liuan/archive/2012/01/09/2317377.html
http://www.cnblogs.com/liuan/archive/2012/01/10/2318300.html
在Qt中使用zxing有多种方式,以下为你详细介绍: ### 使用QZXing库 可以使用QZXing生成和解析二维码与条码。QZXing是一个Qt/QML包装库,可从GitHub下载,其下载地址为:GitHub - ftylitak/qzxing: Qt/QML wrapper library for the ZXing library. 1D/2D barcode image processing library [^1]。 ### 使用zxing-cpp源码 若要在qt5.9工程中使用zxing-cpp,可按如下步骤操作: 1. 下载zxing-cpp源码,获取目录 `zxing-cpp-master\core\src`,该目录包含所有源码。 2. 将 `src` 重命名为 `zxing`,在 `.pro` 文件中添加 `INCLUDEPATH+=$$PWD/zxing`。 3. 把所有源文件添加到pro工程中。若使用了opencv,需将相关源码上传 [^2]。 ### 使用ZXing C++ Lib编译生成的lib文件 ZXing C++ Lib的下载仓库提供了在Visual Studio 2013环境下编译生成的lib文件。此版本基于网络原始版本,并进行了全面的错误修正,还在ZXing基础上增加了基于OpenCV的二维码解析封装。使用该库的详细说明可参考相关博客文章 [^3]。 ### 使用zxing-cpp进行二维码生成与识别(支持中文) 可以利用 `ZXing::ToMatrix` 方法获取二维码图像的像素数据,将其转换成 `QImage` 后在Qt中使用。以下是解码二维码图像的示例代码: ```cpp #include "BarcodeFormat.h" #include "BitMatrix.h" #include "MultiFormatWriter.h" #include "ReadBarcode.h" QImage image = QImage("1212.png"); if (image.format() != QImage::Format_Grayscale8) { image = image.convertToFormat(QImage::Format_Grayscale8); //8位灰度格式 } auto options = ZXing::ReaderOptions() .setCharacterSet(ZXing::CharacterSet::UTF8) .setFormats(ZXing::BarcodeFormat::QRCode) // 明确指定 QR Code .setTryInvert(true) // 允许尝试反色 .setTryRotate(true) // 允许尝试旋转 .setTextMode(ZXing::TextMode::HRI) .setMaxNumberOfSymbols(10); ZXing::ImageView imgView(image.bits(), image.width(), image.height(), ZXing::ImageFormat::Lum, image.bytesPerLine(), 1); auto barcodes = ZXing::ReadBarcodes(imgView, options); for (auto& barcode : barcodes) { qDebug() << "Text: " << QString::fromUtf8(barcode.text()); } ``` 该代码首先读取一张二维码图片,将其转换为8位灰度格式,然后设置解码选项,最后进行解码并输出解码结果 [^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值