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/generators
- Wrapper to create WinRT component
- Wrapper for Android
- Wrapper for WebAssembly
- Python binding
|1D product||1D industrial||2D|
|UPC-A||Code 39||QR Code|
Note: DataBar used to be called RSS.
To read barcodes:
As an example, have a look at
- Load your image into memory (3rd-party library required).
ReadBarcode.h, the simplest API to get a
To write barcodes:
As an example, have a look at
- Create a
MultiFormatWriterinstance with the format you want to generate. Set encoding and margins if needed.
encode()with text content and the image size. This returns a
BitMatrixwhich is a binary image of the barcode where
true== visual black and
false== visual white.
- Convert the bit matrix to your native image format. See also the
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
Standard setup on Windows/macOS/Linux
- Make sure CMake version 3.10 or newer is installed.
- Make sure a C++17 compliant compiler is installed (minimum VS 2017 15.7 / gcc 7 / clang 5)
- See the cmake
BUILD_...options to enable the testing code, python wrapper, etc.
Windows GDIPlus wrapper
- Open CMake GUI, specify
wrappers/gdiplusas source folder in the first input, specify the build output in the second input, and click on Generate.
- At prompt, select "Visual Studio 15 2017" (or "Visual Studio 15 2017 Win64" if you want to build for x64 platform); leave the second input (Optional toolset...) empty; leave "Use default native compilers" checked; and click on Finish to generate the VS project. At the end, you will get a solution (.sln) in your binary output directory that you can open in VS. The project ZXingGdiPlus in the solution will generate a static library.
Windows Universal Platform
- Download and install CMake 3.4 or more recent if it's not already installed.
- Edit the file
wrappers/winrt/BuildWinCom.batto 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.
Note: The original Java-only ZXing project has a very good support for Android, whether you want to use it as external app via Intent or directly integrated into your app. You should consider using it first before trying this library since involving with native code is always more complex than Java-only code. Performance-wise, except for specific usecases, you won't notice the difference!
wrappers/android/jni/Application.mkand adjust for your project.
- On command line,
ndk-build -j <number of your CPU cores>)
- Copy files in
javainto corresponding folders of your Android project.
- Install Emscripten if not done already.
- In an empty build folder, invoke
emcmake cmake <path to zxing-cpp.git/wrappers/wasm>.
cmake --build .to create
- 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.