zxing-cpp/zxing-cpp
GitHub: zxing-cpp/zxing-cpp
ZXing 的 C++ 移植版,提供多格式、高性能的条码编解码能力。
Stars: 1836 | Forks: 530
[](https://github.com/zxing-cpp/zxing-cpp/actions?query=workflow%3ACI)
# ZXing-C++
ZXing-C++ ("zebra crossing") 是一个用 C++ 实现的开放源代码、多格式线性/矩阵条码图像处理库。
它最初是从 Java [ZXing 库](https://github.com/zxing/zxing) 移植而来,但在此基础上进行了进一步开发,现在在运行时和检测性能方面都有了诸多改进。它可以读取和写入多种格式的条码。自 3.0 版本起,默认的写入后端由 [zint 库](https://sourceforge.net/projects/zint/) 提供。
## 功能特性
* 使用纯 C++20 编写(公共 API 兼容 C++17),库本身无第三方依赖
* 线程安全
* 包装器/绑定支持:
| | | |
|:-|:-|:-|
| [Android](wrappers/android/README.md) | [C](wrappers/c/README.md) | [Go](wrappers/go/README.md) |
| [iOS](wrappers/ios/README.md) | [Kotlin/Native](wrappers/kn/README.md) | [.NET](wrappers/dotnet/README.md) |
| [Python](wrappers/python/README.md) | [Qt](wrappers/qt/README.md) | [Rust](wrappers/rust/README.md) |
| [WebAssembly](wrappers/wasm/README.md) | [WinRT](wrappers/winrt/README.md) | [Flutter](https://pub.dev/packages/flutter_zxing)(外部项目) |
## 支持的格式
| 符号体系 | 变体 |
|:----------|:---------|
| ***零售:*** | *(销售点、优惠券)*
| EAN/UPC | EAN-13、EAN-8、EAN-5ᵂ、EAN-2ᵂ、UPC-A、UPC-E、ISBN
| DataBar | 全向、堆叠、受限、扩展、扩展堆叠
| ***工业:*** | *(物流、追踪、制药)*
| Code39 | 标准、扩展、PZN、Code32、(VIN、LOGMARS)
| Code93 |
| Code128 |
| ITF | ITF-14、(DHL Leitcode、DHL Identcode)
| ***矩阵:*** | *(文档、票据、物流、ID)*
| Aztec Code | Aztec Code、Aztec Rune
| Data Matrix | ECC200
| MaxiCode | (部分读取支持)
| PDF417 | PDF417、Compact PDF417、MicroPDF417ᵂ
| QR Code | Model 1ᴿ、Model 2、Micro QR Code、rMQR
| ***其他:*** | *(遗留、细分)*
| Codabar |
| DXFilmEdge |
[注意:]
* ᵂ:仅写入支持
* ᴿ:仅读取支持
* DataBar 曾称为 RSS。
* DataBar、DX Film Edge、MaxiCode、Micro QR Code 和 rMQR Code 在使用 `ZXING_WRITERS=OLD` 配置时,不支持写入。
## 快速入门
### 读取条码:
1. 将图像加载到内存中(需要第三方库)。
2. 调用 [`ReadBarcode.h`](core/src/ReadBarcode.h) 中的 `ReadBarcodes()`,这是获取 `Barcode` 对象列表的最简单 API。
一个非常简单的示例如下:
```
#include "ZXing/ZXingCpp.h"
#include
int main(int argc, char** argv)
{
int width, height;
unsigned char* data;
// load your image data from somewhere. ImageFormat::Lum assumes grey scale image data.
auto image = ZXing::ImageView(data, width, height, ZXing::ImageFormat::Lum);
auto options = ZXing::ReaderOptions().formats(ZXing::BarcodeFormat::QRCode);
auto barcodes = ZXing::ReadBarcodes(image, options);
for (const auto& b : barcodes)
std::cout << ZXing::ToString(b.format()) << ": " << b.text() << "\n";
return 0;
}
```
要了解 API 的全部功能,请查看 [`ZXingReader.cpp`](example/ZXingReader.cpp)。
### 写入条码:
1. 使用 [`CreateBarcode.h`](core/src/CreateBarcode.h) 中的 `CreateBarcodeFrom...()` 创建 `Barcode` 对象。
2. 可以通过 `Barcode::symbol()` 获取位矩阵(1 模块 == 1 像素,无安静区)。
3. 或者,可以使用 [`WriteBarcode.h`](core/src/WriteBarcode.h) 中的 3 个 `WriteBarcodeTo...()` 函数来创建 `Image`、SVG 字符串或 UTF-8 字符串表示。
一个非常简单的示例如下:
```
#include "ZXing/ZXingCpp.h"
#include
int main(int argc, char** argv)
{
auto barcode = ZXing::CreateBarcodeFromText("some text", ZXing::BarcodeFormat::QRCode);
auto svg = ZXing::WriteBarcodeToSVG(barcode);
// see also ZXing::WriteBarcodeToImage()
std::cout << svg << "\n";
return 0;
}
```
有关如何使用 `CreatorOptions` 和 `WriterOptions` 对过程进行参数化的示例,请查看 [`ZXingWriter.cpp`](example/ZXingWriter.cpp)。
### 在线 API 文档
最新的 API 文档可在此处找到:https://zxing-cpp.github.io/zxing-cpp/docs/latest
## Web 演示
- [读取条码](https://zxing-cpp.github.io/zxing-cpp/demo/demo_reader.html)
- [写入条码](https://zxing-cpp.github.io/zxing-cpp/demo/demo_writer.html)
- [从摄像头读取条码](https://zxing-cpp.github.io/zxing-cpp/demo/demo_cam_reader.html)
[注意:这些实时演示不一定始终保持最新。]
## 构建说明
以下是构建该库在 Windows/macOS/Linux 上的通用说明。有关如何构建各个包装器的详细信息,请按照上述链接操作。
1. 确保已安装 [CMake](https://cmake.org) 3.16 或更高版本。Python 模块需要 3.18 或更高版本。
2. 确保安装了足够符合 C++20 规范的编译器(最低 VS 2019 16.10?/ gcc 11 / clang 12?)。
3. 查看 CMake 的 `ZXING_...` 选项以启用测试代码、Python 包装器等。
```
git clone https://github.com/zxing-cpp/zxing-cpp.git --recursive --depth 1
cmake -S zxing-cpp -B zxing-cpp/build -DCMAKE_BUILD_TYPE=Release
cmake --build zxing-cpp/build --parallel --config Release
```
[注意:现成的软件包可用于/作为
[vcpkg](https://github.com/Microsoft/vcpkg/tree/master/ports/nu-book-zxing-cpp),
[conan](https://github.com/conan-io/conan-center-index/tree/master/recipes/zxing-cpp),
[mingw](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-zxing-cpp),
[homebrew](https://formulae.brew.sh/formula/zxing-cpp) 以及一组
[linux 发行版](https://repology.org/project/zxing-cpp/versions)。]
标签:AI工具, Android, Aztec, C++, C++17, C++20, Code128, Code39, Code93, DataBar, Data Matrix, DSL, EAN, Go, HTTP头分析, iOS, ITF, Kotlin, MaxiCode, PDF417, POS, Python, Ruby工具, Rust, UPC, WebAssembly, zint, ZXing, 二维码, 优惠券, 制药, 可视化界面, 图像处理, 图像识别, 多人体追踪, 多格式, 开源库, 搜索引擎爬虫, 数据擦除, 文档, 无后门, 无第三方依赖, 日志审计, 条形码, 条码扫描, 条码生成, 点-of-sale, 物流, 票据, 线程安全, 网络流量审计, 读写条码, 逆向工具, 零售