In the previous post, you have seen how to generate and read different types of barcodes using C#. However, in certain cases, you have to deal with non-English characters. For example, when you work with Arabic, Latin, Greek, or similar languages. In such cases, you may need to encode the characters into Unicode standards i.e. UTF-8. In accordance with that, this article covers how to generate and read barcodes using UTF-8 encoding in C#.
- 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
Aspose.BarCode for .NET is a powerful C# API for barcode generation and recognition. Using the API, you can work with a wide range of barcode symbologies. In addition, the API supports generating barcodes using UTF-8 encoding. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.BarCode
Generate Barcode using UTF-8 Encoding in C#
The following are the steps to generate barcode using UTF-8 encoding.
- First, create an instance of BarcodeGenerator class and specify the barcode type using EncodeTypes.
- Set barcode’s text using BarcodeGenerator.CodeText property.
- Set UTF-8 text encoding using BarcodeGenerator.Parameters.Barcode.QR.CodeTextEncoding property (replace QR according to the barcode type you have specified in BarcodeGenerator constructor).
- Generate barcode using BarcodeGenerator.GenerateBarCodeImage() method and save returned image into a Bitmap object.
- Finally, save the barcode image as a file using Bitmap.Save(String) method.
The following code sample shows how to generate a barcode using UTF-8 encoding in C#.
Read UTF-8 Encoded Barcode using C#
The following are the steps to recognize UTF-8 encoded barcode using C#.
- Use BarCodeReader class to load the barcode image.
- Loop through each BarCodeResult returned by BarCodeReader.ReadBarCodes() method.
- Create an object of the Encoding class and set encoding to UTF-8.
- Get the char array from the bytes returned by the BarCodeResult object.
- Build Unicode string from the characters to get the barcode text.
- Finally, print the retrieved barcode text.
The following code sample shows how to recognize barcodes using UTF-8 encoding in C#.
Get a Free API License
In case you are interested in trying and using the API, you can get a free temporary license.
In this article, you have learned how to generate barcodes using UTF-8 encoding in C#. Furthermore, you have seen how to recognize and read a UTF-8 encoded barcode. You can explore more about the C# barcode API using the documentation.