Generate and Read Barcodes using C++

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.

generate barcode in C++

Barcodes are used to visually represent the data in the machine-readable form. The said technology has proved to be useful especially in the automated checkout systems deployed in stores and supermarkets. Almost every product in the market these days contains a barcode on it. This widespread popularity of the barcode has extended its use cases in various domains. Keeping an eye on the importance of barcodes, a few years ago, Aspose has launched barcode generator and reader API for various platforms. This article aims to showcase how to implement the barcode generator and reader within the C++ applications to dynamically generate and read barcodes.

C++ Barcode Generator and Reader API

Aspose.BarCode for C++ is a feature-rich C++ API for generating and reading a multitude of 1D and 2D barcodes. It lets you generate, customize, and export the barcodes to high-quality images. You can download the library files from the Downloads section. The downloadable package also contains a demo C++ application for you.

The following is the list of barcode symbologies you can generate using Aspose.BarCode for C++:

  • 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 using Aspose.BarCode can be achieved within a couple of lines of code. The following are the steps to perform this operation.

The following code sample shows how to generate a barcode using C++.

The following is the barcode we have generated using the above code.

Generate 2D Barcode (QR or other) using C++

In the previous example, we have created a one-dimensional barcode. Lets now create a two-dimensional barcode such as QR code. The following are the steps to create a QR barcode.

The following code sample shows how to generate a QR barcode using C++.

The following QR code will be generated using the above code.

Generate Customized Barcodes using C++

You can also customize the appearance of the barcode. For example, you can set the foreground color, background color, size, border style and etc. The following ate the steps to customize the barcodes using Aspose.BarCode for C++.

The following code sample shows how to generate a customized barcode using C++.

The following is the customized Aztec barcode we have generated.

Generate Barcodes with a Caption using C++

Barcodes may also contain the caption below or above the barcode. You can set the caption’s text as well as its visibility in the barcode image. The following code sample shows how to generate a barcode with the captions using C++.

The following is a barcode with the above and below captions.

Scan and Read Barcodes using C++

Lets now see how to scan and read the barcodes using Aspose.BarCode for C++. The following are the steps to perform this feature.

  • Create an instance of the BarCodeReader class.
  • Initialize BarCodeReader instance with the barcode’s image file and it’s symbology.
  • Use BarCodeReader->Read() method to retrive the text and type of the barcode.

The following code sample shows how to scan and read a barcode using C++.

Read Barcodes with Multiple Symbologies using C++

Most of the time, an image contains only a single barcode symbology. However, in certain cases, the image may contain barcodes of multiple symbologies at the same time. In such cases, you can provide a list of the barcode symbologies to be scanned and read.

The following code sample shows how to scan an image having multiple barcode symbologies using C++.

Conclusion

In this article, you have learned how to generate barcodes with different symbologies using C++. In addition, the procedure of scanning and reading barcodes is also discussed along with C++ code samples. You can explore more about the API using the documentation.

See Also