在 C# 中整合 Aztec 碼生成功能
使用 cruflbcsnet.dll 進行高性能條碼編碼的專業開發指南。
實作細節
1
在專案中添加對 cruflbcsnet.dll 的引用,並包含 using crUFLBcsNet; 指令。
2
對產生的字串應用 bcsaztec.ttf 字體,以視覺化方式呈現條碼。
AztecGenerator.cs
using System;
using crUFLBcsNet; // 確保已引用 DLL
namespace AztecEncodingApp{
class Program
{
static void Main(string[] args)
{
// 初始化 Barcodesoft Aztec 物件
crUFLBcsNet.CAztec aztec = new crUFLBcsNet.CAztec();
string inputData = "Hello, World!";
// 方法 1:標準編碼
string str = aztec.Encode(inputData);
Console.WriteLine("標準輸出: " + str);
// 方法 2:用於 Crystal Reports 的高級編碼 (EncodeCR)
// 參數 1: 輸入字串
// 參數 2: 索引 (始終設為 0)
// 參數 3: 格式 (0 = 自動選擇)
// 參數 4: 糾錯級別 (0 = 默認 23%)
string str2 = aztec.EncodeCR(inputData, 0, 0, 0);
Console.WriteLine("Crystal Reports 輸出: " + str2);
// 重要提示:請為輸出字串設置 bcsaztec.ttf 字型
}
}}
| 參數 | 值 | SEO 技術說明 |
|---|---|---|
| Index | 0 | 條碼位置的序列索引。 |
| Format | 0 | 啟用自動選擇以獲得最佳 Aztec 尺寸。 |
| Error Correction | 0 | 應用標準的 23% 糾錯級別。 |
Aztec 碼影像生成完整原始碼實作
// 1. 引用必要的命名空間using System;using System.IO;using Barcodesoft.Aztec; namespace AztecExample{ class Program { static void Main(string[] args) { // 實例化條碼引擎 CAztec aztec = new CAztec(); // 將影像生成為位元組陣列 (byte array) // 參數:資料, 寬度, 高度, 格式 (2=PNG), 糾錯等級 byte[] aztecImage = aztec.Image("Hello, World!", 0, 0, 2, 0); if (aztecImage != null) { // 將位元組陣列持久化為實體檔案 File.WriteAllBytes("myAztecBarcode.webp", aztecImage); Console.WriteLine("Aztec 條碼儲存成功。"); } } }}