Aspose.BarCode如何生成和识别UTF-8条形码

作者:控件中国网   出处:控件中国网   2016-04-05 10:41:16   阅读:13

Aspose.BarCode是一款专业的条码生成和识别组件,可以帮助开发人员构建专业的一维和二维条码的生成和识别,可以导出条码为多种图片格式以及从多种图片格式中识别条码,这篇文章主要介绍怎么利用Aspose.BarCode生成和识别UTF-8条码,该条码是一种针对Unicode字符的可变长度的编码,可以以Unicode的标准表示任何字符,可以使用该条码生成任何非英语字符的条码,下面的事例主要以生成和识别Arabic字符的UTF-8条码为例:
 
Bitmap imgBarcode = null;
// set license
Aspose.BarCode.License license = new Aspose.BarCode.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");
}

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat