In this article, I’ll demonstrate how to generate barcodes programmatically using C++. You will also learn how to implement a barcode scanner or reader within your C++ applications.
{{< figure align=center src=“images/Generate-Barcode-in-C.jpg” alt=“generate barcode in C++">}}
Barcodes visually represent data in a machine‑readable form. This technology is essential for automated checkout systems in stores and supermarkets. Almost every product today carries a barcode, extending its use across many industries. Recognizing the importance of barcodes, Aspose launched a barcode generator and reader API for multiple platforms. This article shows how to integrate the barcode generator and reader into C++ applications to dynamically create and read barcodes.
- Generate a barcode using C++
- Generate 2D barcode (QR or other) using C++
- Create barcodes with a customized appearance using C++
- Create barcodes with a caption using C++
- Scan and read barcodes using C++
- Read multiple barcode symbologies using C++
C++ Barcode Generator and Reader API
Aspose.BarCode for C++ is a feature‑rich C++ API for generating and reading a wide range of 1D and 2D barcodes. It lets you generate, customize, and export barcodes as high‑quality images. Download the library from the Downloads page. The package also includes a demo C++ application.
Supported barcode symbologies include:
- Code128
- Code39 Standard
- Code39 Extended
- Code93 Standard
- Code93 Extended
- Code11
- Codabar
- BooklandEAN
- EAN13
- EAN8
- EAN128
- Interleaved2of5
- Standard2of5
- MSI
- Postnet
- Planet
- UPCA
- UPCE
- EAN14(SCC14)
- SSCC18
- ITF14
- BarCode supplement
- Pdf417
- QR
- Datamatrix
- Matrix 2 of 5
- PZN (Pharma Zentral Nummer, Pharmazentralnummer barcode)
- Deutsche Post Identcode
- Aztec
- Australia Post
Generate a Barcode using C++
Generating a barcode with Aspose.BarCode requires only a few lines of code.
- Create a BarcodeGenerator object.
- Initialize it with the desired encode type and text.
- Save the barcode image using
BarcodeGenerator->Save(System::String).
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “generate-barcode.cpp” >}}
The image below shows the generated barcode.
{{< figure align=center src=“images/code39_barcode-1024x298.jpg” alt=”">}}
Generate 2D Barcode (QR or other) using C++
Now let’s create a two‑dimensional barcode such as a QR code.
- Create a BarcodeGenerator object.
- Set the encode type to
EncodeTypes::QRand provide the text. - Save the QR image with
BarcodeGenerator->Save(System::String).
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “generate-qr-barcode.cpp” >}}
The QR code generated by the code appears below.
{{< figure align=center src=“images/QR_Code.jpg” alt="">}}
Generate Customized Barcodes using C++
You can customize barcode appearance, including foreground color, background color, size, and border style.
- Create and initialize a BarcodeGenerator object.
- Access parameters via
BarcodeGenerator->get_Parameters(). - Set the desired properties.
- Save the customized barcode image.
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “generate-custom-barcode.cpp” >}}
Below is a customized Aztec barcode.
{{< figure align=center src=“images/custom_barcode.jpg” alt="">}}
Generate Barcodes with a Caption using C++
Barcodes can include captions above or below the image. You can set caption text and visibility.
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “generate-barcode-with-caption.cpp” >}}
The image shows a barcode with both top and bottom captions.
{{< figure align=center src=“images/barcode_caption-1024x319.jpg” alt="">}}
Scan and Read Barcodes using C++
To scan and read barcodes with Aspose.BarCode for C++:
- Create a BarCodeReader instance.
- Initialize it with the barcode image file and its symbology.
- Call
BarCodeReader->Read()to retrieve the text and type.
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “read-barcode.cpp” >}}
Read Barcodes with Multiple Symbologies using C++
Sometimes an image contains several barcode types. Provide a list of symbologies to scan them all.
{{< gist aspose-com-gists 281552f8ccf17e6b5ae4e313414184a8 “read-multiple-symbologies.cpp” >}}
Conclusion
In this article, you learned how to generate various barcode symbologies in C++ and how to scan and read them. Explore more features in the documentation.