翻譯|使用教程|編輯:李顯亮|2021-02-23 10:02:49.090|閱讀 295 次
概述:在某些情況下,必須處理非英語字符。在這種情況下,可能需要將字符編碼為Unicode標準,即UTF-8。因此,本文介紹了如何使用C#中的UTF-8編碼生成和讀取條形碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在上一篇文章中,學習了如何使用C#生成和讀取不同類型的條形碼。但是,在某些情況下,必須處理非英語字符。例如,當您使用阿拉伯語,拉丁語,希臘語或類似語言時。在這種情況下,可能需要將字符編碼為Unicode標準,即UTF-8。因此,本文介紹了如何使用C#中的UTF-8編碼生成和讀取條形碼。
目前,Aspose.Barcode是強大的C#API,用于條形碼的生成和識別。使用API,可以使用多種條形碼符號。此外,API支持使用UTF-8編碼生成條形碼。,還沒使用過的朋友可以點擊下載最新版Aspose.Barcode。
以下是使用UTF-8編碼生成條形碼的步驟。
以下代碼示例顯示了如何使用C#中的UTF-8編碼生成條形碼。
// 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");
以下是使用C#識別UTF-8編碼條形碼的步驟。
下面的代碼示例演示如何使用C#中的UTF-8編碼識別條形碼。
// 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); } }
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn