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