Created
February 19, 2021 13:14
-
-
Save aspose-com-gists/74edf30d4886c1c1afb0d7f4da68adc1 to your computer and use it in GitHub Desktop.
Generate Barcode using UTF-8 in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a barcode generator | |
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Pdf417); | |
// Set barcode text | |
generator.CodeText = "منحة"; | |
// Set resolution | |
generator.Parameters.Resolution = 400; | |
// Set encoding type | |
generator.Parameters.Barcode.Pdf417.CodeTextEncoding = Encoding.UTF8; | |
// Generate barcode | |
Bitmap imgBarcode = generator.GenerateBarCodeImage(); | |
// Save barcode image | |
imgBarcode.Save("generate-barcode.png"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Recognize the above barcode | |
using (BarCodeReader reader = new BarCodeReader("generate-barcode.png")) | |
{ | |
// Read barcodes | |
foreach (BarCodeResult result in reader.ReadBarCodes()) | |
{ | |
// Set encoding | |
Encoding unicode = Encoding.UTF8; | |
// Get the characters array from the bytes | |
char[] unicodeChars = new char[unicode.GetCharCount(result.CodeBytes, 0, result.CodeBytes.Length)]; | |
unicode.GetChars(result.CodeBytes, 0, result.CodeBytes.Length, unicodeChars, 0); | |
// Build unicode string | |
string strCodeText = new string(unicodeChars); | |
Console.WriteLine(strCodeText); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment