From ede88360adbf5addfb0572f6d212651e4e37d3a1 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 31 Dec 2022 12:25:29 -0600 Subject: [PATCH] add example usage --- Cargo.toml | 2 +- README.md | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 54e4ecf..341f8f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ urlencoding = "2.1.2" uriparse = "0.6.4" chrono = "0.4" chrono-tz = "0.4" -image = {version = "0.24.5", optional = true} +image = {version = "0.24", optional = true} imageproc = {version = "0.23.0", optional = true} unicode-segmentation = "1.10.0" codepage-437 = "0.1.0" diff --git a/README.md b/README.md index 983fa5a..e53dddf 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,32 @@ This is a port of the ZXing (https://github.com/zxing/zxing) java barcode librar Porting of the testing library is incomplete. Porting was done with the rust language in mind, though some parts may resemble java more directly than a proper clean-sheet rust implementation. + +``` +use std::{collections::HashMap, rc::Rc}; + +use rxing::multi::MultipleBarcodeReader; + +use image; + +use rxing; + +fn main() { + let file_name = "test_image.jpeg"; + + let img = image::open(file_name).unwrap(); + + let multi_format_reader = rxing::MultiFormatReader::default(); + let mut scanner = rxing::multi::GenericMultipleBarcodeReader::new(multi_format_reader); + let results = scanner.decodeMultipleWithHints( + &rxing::BinaryBitmap::new(Rc::new(rxing::common::HybridBinarizer::new(Box::new( + rxing::BufferedImageLuminanceSource::new(img), + )))), + &HashMap::new(), + ).expect("decodes"); + + for result in results { + println!("{} -> {}",result.getBarcodeFormat(), result.getText()) + } +} +``` \ No newline at end of file