使用 IRONBARCODE 使用 IronBarcode 的 C# 條碼產生器原始碼 Curtis Chau 更新:2026年1月5日 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 如何使用 NuGet 套件管理器安裝條碼產生器庫? 開啟 Visual Studio,並在套件管理器控制台中使用以下命令安裝 NuGet 套件: Install-Package BarCode 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 1 - 安裝 NuGet 套件支援 .NET 8、.NET 6、.NET Core、.NET Standard 和 .NET Framework,使其與 Windows 應用程式和跨平台 .NET 應用程式相容。 IronBarcode 支援部署到 Docker 容器、Azure 和 Linux 伺服器。 更多詳細資訊和參考文件請參閱Iron Software GitHub 專案。 如何使用 C# 產生簡單的條碼圖像檔案? 只需幾行程式碼即可建立條碼影像。 以下範例展示如何產生條碼並儲存為 PNG 圖檔: using IronBarCode; // Generate a simple barcode and encode the string data var barcode = BarcodeWriter.CreateBarcode("SKU-78432-X", BarcodeWriterEncoding.Code128); // Save the barcode as a PNG image file barcode.SaveAsPng("product-barcode.png"); using IronBarCode; // Generate a simple barcode and encode the string data var barcode = BarcodeWriter.CreateBarcode("SKU-78432-X", BarcodeWriterEncoding.Code128); // Save the barcode as a PNG image file barcode.SaveAsPng("product-barcode.png"); Imports IronBarCode ' Generate a simple barcode and encode the string data Dim barcode = BarcodeWriter.CreateBarcode("SKU-78432-X", BarcodeWriterEncoding.Code128) ' Save the barcode as a PNG image file barcode.SaveAsPng("product-barcode.png") $vbLabelText $csharpLabel BarcodeWriter.CreateBarcode()方法接受一個要編碼的字串和來自BarcodeWriterEncoding條碼格式。 傳回的GeneratedBarcode參考提供了樣式方法和匯出選項,可儲存為 PNG、JPEG、BMP、TIFF、PDF 或 HTML 格式。 輸出 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 2 - 條碼輸出 Code128 與物流和庫存系統相關——它可以對大寫字母、小寫字母、數字和特殊字元進行編碼。 這種條碼類型可確保在運輸設施和零售環境中正確掃描。 如何建立二維碼和其他條碼類型? IronBarcode 支援所有主流條碼格式,包括二維條碼類型,例如 QR 碼和資料矩陣。 使用類似的語法產生二維碼: using IronBarCode; // Create a QR code and encode URL data var qrCode = BarcodeWriter.CreateBarcode( "https://ironsoftware.com", BarcodeWriterEncoding.QRCode ); qrCode.SaveAsPng("website-qr.png"); using IronBarCode; // Create a QR code and encode URL data var qrCode = BarcodeWriter.CreateBarcode( "https://ironsoftware.com", BarcodeWriterEncoding.QRCode ); qrCode.SaveAsPng("website-qr.png"); Imports IronBarCode ' Create a QR code and encode URL data Dim qrCode = BarcodeWriter.CreateBarcode( "https://ironsoftware.com", BarcodeWriterEncoding.QRCode ) qrCode.SaveAsPng("website-qr.png") $vbLabelText $csharpLabel 二維碼條碼類型非常適合儲存網址和更大的資料有效載荷。 該庫會自動處理錯誤修正,確保即使條碼部分損壞,仍可掃描。 輸出 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 3 - 二維碼輸出 對於需要使用EAN-13條碼的零售產品,請產生如下所示的條碼圖像: using IronBarCode; // Generate an EAN-13 barcode compatible with UPC for retail print applications var eanBarcode = BarcodeWriter.CreateBarcode("5901234123457", BarcodeWriterEncoding.EAN13); eanBarcode.SaveAsPng("retail-product.png"); using IronBarCode; // Generate an EAN-13 barcode compatible with UPC for retail print applications var eanBarcode = BarcodeWriter.CreateBarcode("5901234123457", BarcodeWriterEncoding.EAN13); eanBarcode.SaveAsPng("retail-product.png"); Imports IronBarCode ' Generate an EAN-13 barcode compatible with UPC for retail print applications Dim eanBarcode = BarcodeWriter.CreateBarcode("5901234123457", BarcodeWriterEncoding.EAN13) eanBarcode.SaveAsPng("retail-product.png") $vbLabelText $csharpLabel EAN-13 提供與全球銷售點系統相關的詳細資訊。該程式庫基於 .NET 開發人員建立零售應用程式的實務經驗,自動計算校驗位。 輸出 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 4 - EAN-13 條碼輸出 如何創建具有高級樣式選項的精美二維碼? 專業的條碼產生通常需要高級樣式選項來調整顏色和添加註釋。 GeneratedBarcode類別提供了一個流暢的 API,其中包含樣式設定方法: using IronBarCode; using IronSoftware.Drawing; // Create a styled QR code with advanced styling options var styledBarcode = BarcodeWriter .CreateBarcode("INV-2025-001847", BarcodeWriterEncoding.Code128) .ResizeTo(400, 120) .SetMargins(20) .ChangeBarCodeColor(Color.DarkBlue) .AddAnnotationTextAboveBarcode("Invoice Number:") .AddBarcodeValueTextBelowBarcode(); // Verify to ensure proper scanning after styling bool isReadable = styledBarcode.Verify(); Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}"); styledBarcode.SaveAsPng("styled-invoice-barcode.png"); using IronBarCode; using IronSoftware.Drawing; // Create a styled QR code with advanced styling options var styledBarcode = BarcodeWriter .CreateBarcode("INV-2025-001847", BarcodeWriterEncoding.Code128) .ResizeTo(400, 120) .SetMargins(20) .ChangeBarCodeColor(Color.DarkBlue) .AddAnnotationTextAboveBarcode("Invoice Number:") .AddBarcodeValueTextBelowBarcode(); // Verify to ensure proper scanning after styling bool isReadable = styledBarcode.Verify(); Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}"); styledBarcode.SaveAsPng("styled-invoice-barcode.png"); Imports IronBarCode Imports IronSoftware.Drawing ' Create a styled QR code with advanced styling options Dim styledBarcode = BarcodeWriter _ .CreateBarcode("INV-2025-001847", BarcodeWriterEncoding.Code128) _ .ResizeTo(400, 120) _ .SetMargins(20) _ .ChangeBarCodeColor(Color.DarkBlue) _ .AddAnnotationTextAboveBarcode("Invoice Number:") _ .AddBarcodeValueTextBelowBarcode() ' Verify to ensure proper scanning after styling Dim isReadable As Boolean = styledBarcode.Verify() Console.WriteLine($"Barcode verification: {(If(isReadable, "PASS", "FAIL"))}") styledBarcode.SaveAsPng("styled-invoice-barcode.png") $vbLabelText $csharpLabel 流暢的 API 可讓您將樣式方法串聯起來,在一個語句中調整顏色、設定邊距和新增文字。 Verify()方法指示您的條碼是否仍可讀取機器可讀取-確保在應用非標準顏色或調整尺寸至較小尺寸後,在生產中能夠正確掃描。 若要產生多個樣式一致的條碼,請查閱自訂條碼樣式指南,其中提供了有關點陣圖操作和字型自訂的詳細資訊。 如何將條碼匯出為不同的影像格式? 針對不同應用場景,產生多種格式的條碼影像。 該庫支援保存為PNG、JPEG、BMP、TIFF、PDF和HTML格式: using IronBarCode; var barcode = BarcodeWriter.CreateBarcode("EXPORT-TEST", BarcodeWriterEncoding.Code128); // Export barcode images to various formats barcode.SaveAsPng("barcode.png"); // Web compatible image barcode.SaveAsJpeg("barcode.jpg"); // Compressed JPEG format barcode.SaveAsTiff("barcode.tiff"); // High-quality TIFF for print barcode.SaveAsPdf("barcode.pdf"); // PDF document format barcode.SaveAsHtmlFile("barcode.html"); // HTML for web embedding // Get as bitmap stream for web APIs or database storage System.IO.Stream barcodeStream = barcode.ToStream(); System.Drawing.Bitmap bitmapImage = barcode.ToBitmap(); using IronBarCode; var barcode = BarcodeWriter.CreateBarcode("EXPORT-TEST", BarcodeWriterEncoding.Code128); // Export barcode images to various formats barcode.SaveAsPng("barcode.png"); // Web compatible image barcode.SaveAsJpeg("barcode.jpg"); // Compressed JPEG format barcode.SaveAsTiff("barcode.tiff"); // High-quality TIFF for print barcode.SaveAsPdf("barcode.pdf"); // PDF document format barcode.SaveAsHtmlFile("barcode.html"); // HTML for web embedding // Get as bitmap stream for web APIs or database storage System.IO.Stream barcodeStream = barcode.ToStream(); System.Drawing.Bitmap bitmapImage = barcode.ToBitmap(); Imports IronBarCode Dim barcode = BarcodeWriter.CreateBarcode("EXPORT-TEST", BarcodeWriterEncoding.Code128) ' Export barcode images to various formats barcode.SaveAsPng("barcode.png") ' Web compatible image barcode.SaveAsJpeg("barcode.jpg") ' Compressed JPEG format barcode.SaveAsTiff("barcode.tiff") ' High-quality TIFF for print barcode.SaveAsPdf("barcode.pdf") ' PDF document format barcode.SaveAsHtmlFile("barcode.html") ' HTML for web embedding ' Get as bitmap stream for web APIs or database storage Dim barcodeStream As System.IO.Stream = barcode.ToStream() Dim bitmapImage As System.Drawing.Bitmap = barcode.ToBitmap() $vbLabelText $csharpLabel ToStream()方法傳回與 ASP.NET Core Web API 和 Blazor 應用程式相容的條碼資料。 ToBitmap()方法提供System.Drawing.Bitmap引用,以便進行進一步的影像處理。 如需在現有 PDF 文件上新增條碼,請參閱 PDF 條碼新增指南。 輸出 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 5 - PNG 條碼輸出 使用 IronBarcode 的 C# 條碼產生器原始碼:圖 6 - HTML 條碼輸出 支援哪些跨平台 .NET 環境? IronBarcode 支援在所有 .NET 平台上產生條碼。 部署到: Windows 應用程式:桌面應用程式、Windows 服務、IIS Web 伺服器 Linux: Docker 容器、AWS Lambda、Azure Functions macOS:開發和伺服器環境 *行動端: .NET MAUI 與 Xamarin .NET Core 和 .NET Standard:跨平台相容庫 Docker 安裝指南詳細介紹了容器化部署所需的依賴項。 其他部署問題的答案可在故障排除文件中找到。 條碼產生的最佳實踐 在 C# .NET 應用程式中產生條碼影像時,遵循最佳實踐對於確保正確掃描、可讀性和相容性至關重要。 以下是一些需要牢記的準則: *選擇合適的條碼格式:*選擇符合您使用場景的條碼格式,無論是用於儲存 URL 和資料的二維碼、用於庫存追蹤的 Code 128,還是用於零售產品的 EAN-13。 IronBarcode 支援多種條碼格式,因此您可以產生最適合您的 .NET 應用程式的條碼類型。 確保正確掃描:始終在條碼影像周圍留出足夠的邊距(靜區)。 對於條碼掃描器來說,這個空白區域對於準確偵測和解碼條碼至關重要,尤其是在列印或顯示於不同裝置上時。 利用進階樣式選項: IronBarcode 提供進階樣式選項,您可以調整字型、顏色和大小。自訂條碼影像可提高可讀性,使其與您的應用程式設計無縫融合,同時確保與掃描裝置相容。 有效率地產生多個條碼:**如果您的應用程式需要產生多個條碼,請使用批次或循環來自動化流程。 這種方法不僅可以節省時間,還可以確保所有產生的條碼影像的一致性。 *測試和驗證條碼影像:在部署解決方案之前,請務必在各種掃描器和環境中測試條碼影像。 IronBarcode 提供內建的驗證方法,以確認您的條碼可讀且符合業界標準。 遵循這些最佳實踐,您可以產生與各種系統和裝置相容的高品質條碼影像,從而確保您的 .NET 應用程式能夠正確掃描並實現可靠的效能。 結論 本 C# 條碼產生器教學課程示範如何使用 IronBarcode 產生條碼影像。 程式碼範例涵蓋了創建簡單的條碼類型、生成樣式化的二維碼以及導出為 PNG、JPEG、TIFF、BMP 和 PDF 格式——所有這些都與 .NET Core、.NET Standard 和 Windows 應用程式相容。 下載 IronBarcode,為您的 .NET 應用程式新增條碼功能。 探索從$799起的授權選項,或開始 30 天免費試用,在您的環境中產生條碼影像。 常見問題解答 如何使用 NuGet 套件管理器安裝 IronBarcode? 若要透過 NuGet 套件管理員安裝 IronBarcode,請開啟 Visual Studio,導覽至“工具”->“NuGet 套件管理員”->“管理解決方案的 NuGet 套件”,搜尋“IronBarcode”,然後按一下「安裝」。 我可以使用 IronBarcode 產生哪些類型的條碼? IronBarcode 支援產生各種條碼類型,包括 QR 碼、Code 39、Code 128、UPC、EAN 等。 IronBarcode 能否產生不同影像格式的條碼? 是的,IronBarcode 可以產生各種影像格式的條碼,例如 PNG、JPEG、GIF、BMP 和 TIFF。 IronBarcode 與 .NET Core 相容嗎? 是的,IronBarcode 與 .NET Core 完全相容,讓您可以將條碼生成整合到跨平台應用程式中。 如何使用 IronBarcode 自訂條碼的外觀? IronBarcode 提供自訂選項,例如設定條碼的顏色、背景顏色、標籤、大小等,以滿足您的需求。 IronBarcode是否支援條碼讀取和掃描? 是的,IronBarcode 不僅可以產生條碼,還支援從影像和文件中讀取和掃描條碼。 使用 IronBarcode 有哪些系統需求? IronBarcode 需要 .NET 環境。它相容於 .NET Framework 4.0 及以上版本,以及 .NET Core 2.0 及以上版本。 我可以使用 IronBarcode 大量產生條碼嗎? 是的,IronBarcode 允許您透過遍歷資料並以程式設計方式建立條碼來批次產生條碼。 IronBarcode有試用版嗎? 是的,IronBarcode 提供免費試用版,您可以在購買授權之前使用該版本來評估其功能。 IronBarcode 用戶可以獲得哪些類型的支援? IronBarcode 提供全面的支持,包括文件、教學課程和專門的支援團隊,以協助您解決可能遇到的任何問題。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 更新2026年1月22日 ASP.NET 條碼掃描器教學:C# 條碼產生器指南 學習如何使用 IronBarcode 在 ASP.NET 中掃描條碼 閱讀更多 發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多 發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多 如何使用VB.NET在Crystal Reports中列印條碼C# 從字串產生條碼:IronBarc...
發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多
發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多