README.md
1[![Build Status](https://github.com/nu-book/zxing-cpp/workflows/CI/badge.svg?branch=master)](https://github.com/nu-book/zxing-cpp/actions?query=workflow%3ACI)
2
3# ZXing-C++
4
5ZXing-C++ ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in C++.
6
7It was originally ported from the Java [ZXing Library](https://github.com/zxing/zxing) but has been developed further and now includes many improvements in terms of quality and performance. It can both read and write barcodes in a number of formats.
8
9## Features
10
11* In pure C++17, no third-party dependencies
12* Stateless, thread-safe readers/scanners and writers/generators
13* Wrapper/Bindings for:
14 * WinRT
15 * Android
16 * WebAssembly
17 * [Python](wrappers/python/README.md)
18
19## Supported Formats
20
21| 1D product | 1D industrial | 2D
22| ---------- | ----------------- | --------------
23| UPC-A | Code 39 | QR Code
24| UPC-E | Code 93 | DataMatrix
25| EAN-8 | Code 128 | Aztec
26| EAN-13 | Codabar | PDF417
27| DataBar | ITF | MaxiCode (beta)
28| | DataBar Expanded |
29
30Note: DataBar used to be called RSS.
31
32## Getting Started
33
34### To read barcodes:
35As an example, have a look at [`ZXingReader.cpp`](example/ZXingReader.cpp).
361. Load your image into memory (3rd-party library required).
372. Call `ReadBarcode()` from [`ReadBarcode.h`](core/src/ReadBarcode.h), the simplest API to get a `Result`.
38
39### To write barcodes:
40As an example, have a look at [`ZXingWriter.cpp`](example/ZXingWriter.cpp).
411. Create a [`MultiFormatWriter`](core/src/MultiFormatWriter.h) instance with the format you want to generate. Set encoding and margins if needed.
422. Call `encode()` with text content and the image size. This returns a [`BitMatrix`](core/src/BitMatrix.h) which is a binary image of the barcode where `true` == visual black and `false` == visual white.
433. Convert the bit matrix to your native image format. See also the `ToMatrix<T>(BitMatrix&)` helper function.
44
45## Web Demos
46- [Read barcodes](https://nu-book.github.io/zxing-cpp/demo_reader.html)
47- [Write barcodes](https://nu-book.github.io/zxing-cpp/demo_writer.html)
48- [Scan with camera](https://nu-book.github.io/zxing-cpp/zxing_viddemo.html)
49
50## WinRT Package
51A nuget package is available for WinRT: [huycn.zxingcpp.winrt](https://www.nuget.org/packages/huycn.zxingcpp.winrt).
52To install it, run the following command in the Package Manager Console
53```sh
54PM> Install-Package huycn.zxingcpp.winrt
55```
56
57## Build Instructions
58
59### Standard setup on Windows/macOS/Linux
601. Make sure [CMake](https://cmake.org) version 3.10 or newer is installed.
612. Make sure a C++17 compliant compiler is installed (minimum VS 2019 16.8 / gcc 7 / clang 5)
623. See the cmake `BUILD_...` options to enable the testing code, python wrapper, etc.
63
64### Windows Universal Platform
651. Download and install [CMake](https://cmake.org) 3.4 or more recent if it's not already installed.
662. Edit the file [`wrappers/winrt/BuildWinCom.bat`](wrappers/winrt/BuildWinCom.bat) to adjust the path to your CMake installation.
673. Double-click on the batch script to run it.
684. If the build succeeds, it will put the results in the folder UAP which is ready-to-use SDK extension.
69
70### Android
711. Install AndroidStudio including NDK and CMake (see 'SDK Tools').
722. Open the project in folder [wrappers/android](wrappers/android).
733. The project contains 2 modules: `zxingcpp` is the wrapper library, `app` is the demo app using `zxingcpp`
74
75### WebAssembly
761. [Install Emscripten](https://kripken.github.io/emscripten-site/docs/getting_started/) if not done already.
772. In an empty build folder, invoke `emcmake cmake <path to zxing-cpp.git/wrappers/wasm>`.
783. Invoke `cmake --build .` to create `zxing.js` and `zxing.wasm` (and `_reader`/`_writer` versions).
794. To see how to include these into a working HTML page, have a look at the [reader](wrappers/wasm/demo_reader.html) and [writer](wrappers/wasm/demo_writer.html) demos.
805. To quickly test your build, copy those demo files into your build directory and run e.g. `emrun --serve_after_close demo_reader.html`.
81
82You can also download the latest build output from the continuous integration system from the [Actions](https://github.com/nu-book/zxing-cpp/actions) tab. Look for 'wasm-artifacts'. Also check out the [live demos](https://nu-book.github.io/zxing-cpp/).
83