mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-25 20:02:34 +00:00
add example usage
This commit is contained in:
29
README.md
29
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())
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user