Aspose.BarCode是一款专业的条码生成和识别组件,可以帮助开发人员构建专业的一维和二维条码的生成和识别,可以导出条码为多种图片格式以及从多种图片格式中识别条码,这篇文章主要介绍怎么利用
Aspose.BarCode生成和识别UTF-8条码,该条码是一种针对Unicode字符的可变长度的编码,可以以Unicode的标准表示任何字符,可以使用该条码生成任何非英语字符的条码,下面的事例主要以生成和识别Arabic字符的UTF-8条码为例:
Bitmap imgBarcode = null;
// set license
license.SetLicense("c:\\Aspose.Total.lic");
try
{
// generate the barcode
BarCodeBuilder objBarCodeBuilder = new BarCodeBuilder();
objBarCodeBuilder.SymbologyType =
Aspose.BarCode.Symbology.MacroPdf417;
// set the codetext by converting it into unicode byte array
byte[] byteArray = Encoding.Unicode.GetBytes("منحة");
objBarCodeBuilder.SetCodeText(byteArray);
imgBarcode = objBarCodeBuilder.GenerateBarCodeImage();
imgBarcode.Save("c:\\barcodes.png");
// recognize the above barcode
BarCodeReader reader = new BarCodeReader("c:\\barcodes.png");
while(reader.Read())
{
Encoding unicode = Encoding.Unicode;
// get the characters array from the bytes
char[] unicodeChars = new char[unicode.GetCharCount(reader. GetCodeBytes(), 0, reader. GetCodeBytes().Length)];
unicode.GetChars(reader. GetCodeBytes(), 0, reader. GetCodeBytes().Length, unicodeChars, 0);
// build unicode string
string strCodeText = new string(unicodeChars);
System.Console.WriteLine(strCodeText);
}
reader.Close();
}
catch (Exception ex)
{
System.Console.WriteLine("No BarCode found");
}