| Crates.io | zbar-src |
| lib.rs | zbar-src |
| version | 0.1.5 |
| created_at | 2025-11-19 15:02:24.862082+00 |
| updated_at | 2025-11-19 18:03:10.7035+00 |
| description | Bundled ZBar C library source code for static linking |
| homepage | https://github.com/kookyleo/zbar-pack |
| repository | https://github.com/kookyleo/zbar-pack |
| max_upload_size | |
| id | 1940220 |
| size | 1,264,632 |
zbar-pack 是一个 ZBar 条码扫描库的 Rust 包装,提供静态链接和跨平台支持。
在 Cargo.toml 中添加:
[dependencies]
zbar-pack = "0.1"
use zbar_pack::{ImageScanner, Image, SymbolType};
fn main() {
// 创建扫描器
let mut scanner = ImageScanner::new().unwrap();
// 配置扫描器 (可选)
scanner.set_config(SymbolType::QRCODE, 0, 1).unwrap();
// 从灰度图像数据创建图像
let image = Image::from_gray(&data, width, height).unwrap();
// 扫描图像
let symbols = scanner.scan_image(&image).unwrap();
// 遍历识别到的符号
for symbol in symbols {
println!("类型: {:?}", symbol.symbol_type());
println!("数据: {}", symbol.data());
println!("质量: {}", symbol.quality());
}
}
vendored (默认): 编译并静态链接内置的 ZBar 源码system: 使用 pkg-config 查找系统安装的 ZBar 库dynamic: 动态链接系统 ZBar 库all-codecs (默认): 启用所有编解码器minimal: 最小化构建,需手动启用需要的编解码器codec-qrcode: QR 码codec-ean: EAN/UPC 系列codec-code128: Code 128codec-code93: Code 93codec-code39: Code 39codec-codabar: Codabarcodec-i25: Interleaved 2 of 5codec-databar: GS1 DataBarcodec-sqcode: SQ 码# 仅支持 QR 码的最小化构建
[dependencies]
zbar-pack = { version = "0.1", default-features = false, features = ["vendored", "codec-qrcode"] }
# 使用系统 ZBar 库
[dependencies]
zbar-pack = { version = "0.1", default-features = false, features = ["system"] }
# 安装 musl 工具链
rustup target add x86_64-unknown-linux-musl
# 编译静态可执行文件
cargo build --release --target x86_64-unknown-linux-musl
本项目在 vendored 模式下静态链接 ZBar (LGPLv2.1+),为满足 LGPL 要求:
源码可获取性
zbar-src/vendor/zbar-0.23.93/库可替换性
system feature 可切换到系统 ZBar 库版本对齐承诺
完整文档
建议在以下场景使用 system 模式:
为符合 crates.io 的体积限制:
# 清理构建缓存
cargo clean
# 尝试使用 system 模式
cargo build --no-default-features --features system
确保使用正确的目标三元组:
cargo build --target x86_64-unknown-linux-musl
确保安装了 Visual Studio Build Tools 或完整的 Visual Studio。
欢迎提交 Issue 和 Pull Request!
详见 CHANGELOG.md
kookyleo kookyleo@gmail.com
Apache-2.0 (本 Rust 包装)
ZBar 库遵循 LGPLv2.1+ 许可证,详见 zbar-src/vendor/zbar-0.23.93/LICENSE.md