ZXing-C++ ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in C++.
It was originally ported from the Java ZXing Library 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.
- In pure C++17, no third-party dependencies
- Stateless, thread-safe readers/scanners and writers/generators
- Wrapper/Bindings for:
- WinRT
- Android
- WebAssembly
- Python
1D product | 1D industrial | 2D |
---|---|---|
UPC-A | Code 39 | QR Code |
UPC-E | Code 93 | DataMatrix |
EAN-8 | Code 128 | Aztec |
EAN-13 | Codabar | PDF417 |
DataBar | ITF | MaxiCode (beta) |
DataBar Expanded |
Note: DataBar used to be called RSS.
As an example, have a look at ZXingReader.cpp
.
- Load your image into memory (3rd-party library required).
- Call
ReadBarcode()
fromReadBarcode.h
, the simplest API to get aResult
.
As an example, have a look at ZXingWriter.cpp
.
- Create a
MultiFormatWriter
instance with the format you want to generate. Set encoding and margins if needed. - Call
encode()
with text content and the image size. This returns aBitMatrix
which is a binary image of the barcode wheretrue
== visual black andfalse
== visual white. - Convert the bit matrix to your native image format. See also the
ToMatrix<T>(BitMatrix&)
helper function.
A nuget package is available for WinRT: huycn.zxingcpp.winrt. To install it, run the following command in the Package Manager Console
PM> Install-Package huycn.zxingcpp.winrt
- Make sure CMake version 3.10 or newer is installed.
- Make sure a C++17 compliant compiler is installed (minimum VS 2019 16.8 / gcc 7 / clang 5)
- See the cmake
BUILD_...
options to enable the testing code, python wrapper, etc.
- Download and install CMake 3.4 or more recent if it's not already installed.
- Edit the file
wrappers/winrt/BuildWinCom.bat
to adjust the path to your CMake installation. - Double-click on the batch script to run it.
- If the build succeeds, it will put the results in the folder UAP which is ready-to-use SDK extension.
- Install AndroidStudio including NDK and CMake (see 'SDK Tools').
- Open the project in folder wrappers/android.
- The project contains 2 modules:
zxingcpp
is the wrapper library,app
is the demo app usingzxingcpp
- Install Emscripten if not done already.
- In an empty build folder, invoke
emcmake cmake <path to zxing-cpp.git/wrappers/wasm>
. - Invoke
cmake --build .
to createzxing.js
andzxing.wasm
(and_reader
/_writer
versions). - To see how to include these into a working HTML page, have a look at the reader and writer demos.
- To quickly test your build, copy those demo files into your build directory and run e.g.
emrun --serve_after_close demo_reader.html
.
You can also download the latest build output from the continuous integration system from the Actions tab. Look for 'wasm-artifacts'. Also check out the live demos.