This project is a C++ port of ZXing Library.
- In pure C++14, no third-party dependencies
- Stateless, thread-safe readers/generators
- Wrapper to create WinRT component
- Wrapper for Android
- Wrapper for WebAssembly
Same as ZXing, following barcode are supported:
1D product | 1D industrial | 2D |
---|---|---|
UPC-A | Code 39 | QR Code |
UPC-E | Code 93 | Data Matrix |
EAN-8 | Code 128 | Aztec (beta) |
EAN-13 | Codabar | PDF 417 (beta) |
ITF | ||
RSS-14 | ||
RSS-Expanded |
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
The wrappers export very simple API to use, check BarcodeReader
and BarcodeGenerator
in each wrapper.
For more fine-grain control in scanning process, check MultiFormatReader
class. For more customization when generating particular barcode format, you need to instantiate appropriate writer, see MultiFormatWriter
for more details.
- Download and install CMake if it's not already installed.
- Open CMake GUI, specify
wrappers/gdiplus
as source folder in the first input, specify the build output in the second input, and click on Generate. - At prompt, select "Visual Studio 14 2015" (or "Visual Studio 14 2015 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.
- 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.
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!
- Edit
wrappers/android/jni/Application.mk
and adjust for your project. - On command line,
cd
intowrappers/android/jni
, typendk-build
(orndk-build -j <number of your CPU cores>
) - Copy files in
libs
andjava
into corresponding folders of your Android project.
- Install Emscripten if not done already.
- In a empty build folder, invoke
cmake
fromemconfigure
create Makefile, usingwrappers/wasm/Toolchain-Emscripten.cmake
as toolchain file. For example:
EMSCRIPTEN_PATH=<path to your Emscripten installation, e.g. ~/emsdk/emscripten/tag-1.38.21>
SOURCE_BASEDIR=<zxing-cpp-dir/wrappers/wasm>
emconfigure cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$SOURCE_BASEDIR/Toolchain-Emscripten.cmake" -DEMSCRIPTEN_ROOT_PATH="$EMSCRIPTEN_PATH" "$SOURCE_BASEDIR"
- Invoke emmake to create
zxing.js
andzxing.wasm
emmake make
- Copy these two files to your web folder and create HTML page that includes
zxing.js
.
See usage example of exported functions from demos.
By default, both encoder and decoder are included. If you don't plan to use either of them, you can disable it to reduce generated code size. To do so, in the line emconfigure cmake ...
above, pass -ENABLE_ENCODERS=0
to disable encoders or -ENABLE_DECODERS=0
to disable decoders.
Wrappers are provided as convenient way to work with native image format. You still can use the library without a wrapper.
- Create a
LuminanceSource
instance. This interface abstracts an image source. You will need a third-party library to read your images. If you already have an image uncompressed in memory and you know its layout, you can easily go withGenericLuminanceSource
. Otherwise, you will need to come up with your own implementation of the interface. - Use the
LuminanceSource
instance above to create an instance ofBinaryBitmap
. You have choices betweenHybridBinarizer
orGlobalHistogramBinarizer
. See class document in header files for more details on theses choices. - Create an instance of
MultiFormatReader
with appropriate hints. Pay attention topossibleFormats()
,shouldTryHarder()
,shouldTryRotate()
. These parameters will affect accuracy as well as reader's speed. - Call
MultiFormatReader::read()
with theBinaryImage
created above to read your barcodes.
- 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 anBitMatrix
which kind of binary image of the barcode wheretrue
== visual black andfalse
== visual white. - Convert the bit matrix to your native image format.