C# Generate Barcodes with UTF-8 Encoding

In our previous post, we explored how to generate and read various types of barcodes using C#. When dealing with languages that include non-English characters—such as Arabic, Latin, or Greek—it’s crucial to encode these characters using Unicode standards, specifically UTF-8. This article will walk you through the steps to generate and read barcodes using UTF-8 encoding in C#.

Table of Contents

C# API to Generate Barcodes using UTF-8 Encoding

The Aspose.BarCode for .NET API is a robust solution for barcode generation and recognition in C#. It supports a wide range of barcode symbologies and allows you to generate barcodes using UTF-8 encoding. You can easily download the API or install it via NuGet with the following command:

PM> Install-Package Aspose.BarCode

Generate Barcode using UTF-8 Encoding in C#

To generate a barcode using UTF-8 encoding, follow these steps:

  1. Create an Instance: Instantiate the BarcodeGenerator class and specify the barcode type using EncodeTypes.
  2. Set Barcode Text: Use the BarcodeGenerator.CodeText property to define the text for the barcode.
  3. Specify Encoding: Indicate UTF-8 text encoding with the BarcodeGenerator.Parameters.Barcode.QR.CodeTextEncoding property (ensure to replace QR with the appropriate barcode type defined in the BarcodeGenerator constructor).
  4. Generate Barcode: Call the BarcodeGenerator.GenerateBarCodeImage method to create the barcode, saving the returned image in a Bitmap object.
  5. Save the Image: Finally, save the barcode image as a file using the Bitmap.Save(String) method.

Here’s a code sample demonstrating how to generate a barcode using UTF-8 encoding in C#:

Read UTF-8 Encoded Barcode using C#

To recognize a UTF-8 encoded barcode using C#, follow these steps:

  1. Load the Barcode Image: Use the BarCodeReader class to load your barcode image.
  2. Process Results: Loop through each BarCodeResult returned by the BarCodeReader.ReadBarCodes() method.
  3. Set Encoding: Create an instance of the Encoding class and set it to UTF-8.
  4. Retrieve Character Array: Access the character array from the bytes returned by the BarCodeResult object.
  5. Construct a String: Build a Unicode string from the characters to obtain the barcode text.
  6. Output the Text: Finally, print the retrieved barcode text.

Here’s a code sample showing how to recognize barcodes using UTF-8 encoding in C#:

Get a Free API License

If you’re interested in trying out the API, you can get a free temporary license.

Conclusion

In this article, you learned how to generate and read barcodes using UTF-8 encoding in C#. With the Aspose Plugin, you can efficiently manage diverse character sets. For further exploration, check out the documentation for more insights into the C# barcode API.