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
- Generate Barcode with UTF-8 Encoding in C#
- Read Barcode with UTF-8 Encoding in C#
- Get a Free API License
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:
- Create an Instance: Instantiate the BarcodeGenerator class and specify the barcode type using EncodeTypes.
- Set Barcode Text: Use the BarcodeGenerator.CodeText property to define the text for the barcode.
- 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).
- Generate Barcode: Call the BarcodeGenerator.GenerateBarCodeImage method to create the barcode, saving the returned image in a Bitmap object.
- 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:
- Load the Barcode Image: Use the BarCodeReader class to load your barcode image.
- Process Results: Loop through each BarCodeResult returned by the BarCodeReader.ReadBarCodes() method.
- Set Encoding: Create an instance of the Encoding class and set it to UTF-8.
- Retrieve Character Array: Access the character array from the bytes returned by the BarCodeResult object.
- Construct a String: Build a Unicode string from the characters to obtain the barcode text.
- 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.