跳過到頁腳內容
使用IRONBARCODE

如何使用IronBarcode在C#中生成QR Code

IronBarcode可讓.NET開發人員能夠使用其 QRCodeWriter 類別有效地建立二維碼。 它支援自訂徽標、顏色、多種輸出格式以及跨平台部署,包括 Windows、Linux、macOS 和行動裝置。

本指南示範如何使用IronBarcode為生產系統產生二維碼。 IronBarcode 的 API 遵循.NET規範,同時提供企業應用程式所需的效能和可靠性。 該程式庫提供完整的文檔,並支援在 Windows、Linux、macOS 和行動平台上部署。 如需全面了解所有功能,請瀏覽功能頁面條碼快速入門指南提供可立即上手操作的範例,協助您快速入門。

使用IronBarcode產生二維碼有哪些好處?

為什麼選擇IronBarcode而不是其他函式庫?

如何使用IronBarcode產生二維碼?

以下各節將示範遵循 SOLID 原則的生產就緒程式碼。 您將學習創建各種類型的二維碼,實現自訂樣式,並確保可靠的掃描效能。 此庫的功能包括支援除二維碼之外的一維二維條碼。 對於更進階的場景,請查閱API 參考文件以取得完整的方法簽名。 瀏覽示範視頻,了解 IronBarcode 的實際功能。

如何建立一個新專案?

開啟 Visual Studio,從"檔案"選單中選擇"新專案" 。 對於企業部署,請考慮查看MSI 安裝程式指南以進行自動安裝。 入門概覽提供了完整的設定說明。

選擇控制台應用程式模板,然後按一下"下一步"。

輸入您喜歡的項目名稱(例如二維碼產生器),並指定項目位置。 點選"下一步"

從下拉清單中選擇.NET Framework ( .NET 6.0(長期支援) ),然後按一下"建立"。 IronBarcode支援所有現代.NET版本,詳情請參閱相容性文件。 有關具體的平台要求,請查看Blazor整合指南。

有哪些安裝方法?

使用四種適用於不同工作流程的方法之一來安裝IronBarcode 。 圖書館的現場演示展示了即時條碼識別功能。 如需快速測試,請查看條碼快速入門範例

如何使用 Visual Studio 的套件管理器 UI 進行安裝?

前往"工具" > "NuGet套件管理器" > "管理解決方案的NuGet套件"…

或在解決方案資源管理器中右鍵單擊您的項目,然後選擇"管理NuGet套件..."

點選"瀏覽" ,搜尋"條碼" ,選擇"IronBarcode" ,選擇您的項目,然後點選"安裝"。 有關特定平台的安裝,請參閱NuGet套件指南。 如果遇到問題,請參閱NuGet故障排除指南。 該程式庫支援多種部署方案,包括AWS LambdaAzure Functions

如何使用軟體套件管理器控制台進行安裝?

開啟"工具" > "NuGet套件管理員" > "套件管理員控制台" ,然後執行:

Install-Package BarCode

這會將庫安裝到您目前的專案中。 對於容器化部署,請遵循Docker 設定指南。 使用許可證金鑰時,請確保針對您的部署環境進行正確配置。

如何從NuGet或IronBarcode網站下載?

從NuGet Gallery 網站下載或造訪 IronBarcode 的主頁取得最新的.NET條碼 DLL。 在解決方案資源管理器中,透過"新增" > "引用"將 DLL 新增到您的專案中。 若要追蹤 DLL 問題,請參閱缺少 DLL 指南。 遇到執行階段問題時,請參閱執行階段複製異常指南

如何建立和自訂二維碼圖像?

如何產生基本的二維碼?

使用 QRCodeWriter 類別中的 CreateQrCode 方法建立二維碼。 有關完整範例,請參閱C# 二維碼產生器教學。 該庫支援創建各種格式的條碼圖像

using IronBarCode;

// Basic QR code generation with medium error correction
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0);
qrCode.SaveAsPng("MyQR.png");

// Generate QR code with automatic sizing and highest error correction
var autoQr = QRCodeWriter.CreateQrCode("Automatic sizing example");
autoQr.SaveAsJpeg("AutoQR.jpg");

// Production-ready QR code with validation
public GeneratedBarcode CreateValidatedQrCode(string data, int size = 600)
{
    if (string.IsNullOrWhiteSpace(data))
        throw new ArgumentException("Data cannot be empty");

    if (data.Length > 2953) // QR Code capacity at highest error correction
        throw new ArgumentException("Data exceeds QR code capacity");

    var qr = QRCodeWriter.CreateQrCode(data, size, QRCodeWriter.QrErrorCorrectionLevel.High);
    qr.VerifyQrCode(); // Verify the generated code is valid
    return qr;
}
using IronBarCode;

// Basic QR code generation with medium error correction
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium, 0);
qrCode.SaveAsPng("MyQR.png");

// Generate QR code with automatic sizing and highest error correction
var autoQr = QRCodeWriter.CreateQrCode("Automatic sizing example");
autoQr.SaveAsJpeg("AutoQR.jpg");

// Production-ready QR code with validation
public GeneratedBarcode CreateValidatedQrCode(string data, int size = 600)
{
    if (string.IsNullOrWhiteSpace(data))
        throw new ArgumentException("Data cannot be empty");

    if (data.Length > 2953) // QR Code capacity at highest error correction
        throw new ArgumentException("Data exceeds QR code capacity");

    var qr = QRCodeWriter.CreateQrCode(data, size, QRCodeWriter.QrErrorCorrectionLevel.High);
    qr.VerifyQrCode(); // Verify the generated code is valid
    return qr;
}
$vbLabelText   $csharpLabel

CreateQrCode 方法接受:

  • 必填:要編碼的資料(字串或流)
  • 可選:圖形尺寸(預設 500x500 像素)
  • 可選:糾錯等級(低 7%,中 15%,高 25%,最高 30%)
  • 可選:二維碼版本號(0 表示自動)

對於高效能批次處理,請使用非同步操作自訂樣式。 在不完美條件下工作時,請使用容錯功能條碼讀取教學示範如何驗證產生的條碼。

我可以在二維碼中編碼哪些資料類型?

生產應用中常見的二維碼資料類型包括從各種來源建立條碼。 有關詳細範例,請參閱建立二維碼範例。 IronBarcode支援Unicode條碼,用於國際字元編碼:

URL二維碼:

// Generate QR code for website URL
var urlQr = QRCodeWriter.CreateQrCode("___PROTECTED_URL_76___", 800);
urlQr.SetMargins(10); // Add quiet zone
urlQr.SaveAsPng("campaign-qr.png");

// Advanced URL QR code with tracking
public GeneratedBarcode CreateTrackableUrlQr(string baseUrl, Dictionary<string, string> utmParams)
{
    var uriBuilder = new UriBuilder(baseUrl);
    var query = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);

    foreach (var param in utmParams)
        query[param.Key] = param.Value;

    uriBuilder.Query = query.ToString();
    var qr = QRCodeWriter.CreateQrCode(uriBuilder.ToString(), 1000);
    return qr;
}
// Generate QR code for website URL
var urlQr = QRCodeWriter.CreateQrCode("___PROTECTED_URL_76___", 800);
urlQr.SetMargins(10); // Add quiet zone
urlQr.SaveAsPng("campaign-qr.png");

// Advanced URL QR code with tracking
public GeneratedBarcode CreateTrackableUrlQr(string baseUrl, Dictionary<string, string> utmParams)
{
    var uriBuilder = new UriBuilder(baseUrl);
    var query = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);

    foreach (var param in utmParams)
        query[param.Key] = param.Value;

    uriBuilder.Query = query.ToString();
    var qr = QRCodeWriter.CreateQrCode(uriBuilder.ToString(), 1000);
    return qr;
}
$vbLabelText   $csharpLabel

vCard 聯絡資訊:

string vCard = @"BEGIN:VCARD
VERSION:3.0
FN:John Smith
ORG:Tech Corp
TEL:+1-555-0123
EMAIL:john@example.com
END:VCARD";

var contactQr = QRCodeWriter.CreateQrCode(vCard, 600, QRCodeWriter.QrErrorCorrectionLevel.Medium);
contactQr.SaveAsPng("contact-card.png");
string vCard = @"BEGIN:VCARD
VERSION:3.0
FN:John Smith
ORG:Tech Corp
TEL:+1-555-0123
EMAIL:john@example.com
END:VCARD";

var contactQr = QRCodeWriter.CreateQrCode(vCard, 600, QRCodeWriter.QrErrorCorrectionLevel.Medium);
contactQr.SaveAsPng("contact-card.png");
$vbLabelText   $csharpLabel

WiFi 配置:

string wifiConfig = "WIFI:T:WPA;S:NetworkName;P:Password123;;";
var wifiQr = QRCodeWriter.CreateQrCode(wifiConfig, 500);
wifiQr.SaveAsPng("wifi-config.png");
string wifiConfig = "WIFI:T:WPA;S:NetworkName;P:Password123;;";
var wifiQr = QRCodeWriter.CreateQrCode(wifiConfig, 500);
wifiQr.SaveAsPng("wifi-config.png");
$vbLabelText   $csharpLabel

IronBarcode處理國際字元的Unicode 支持,並支援Micro QR 和 rMQR等格式,適用於空間受限的應用。 對於特殊格式,請探索新的格式里程碑。 在使用特殊資料格式時,該庫可以從流中讀取資料並將其導出為流,從而實現高效的記憶體使用。

如何新增徽標和自訂樣式?

使用 CreateQrCodeWithLogo 將公司徽標新增至二維碼。 有關完整的樣式選項,請參閱自訂二維碼範例二維碼樣式指南。 該庫還支援所有條碼類型的通用條碼樣式

// Create QR code with embedded logo
var qrWithLogo = QRCodeWriter.CreateQrCodeWithLogo("Hello World", "logo.png", 500);
qrWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkRed);
qrWithLogo.SaveAsPng("Logo_QR_Code.png");

// Advanced logo customization
var logo = new QRCodeLogo("company-logo.png")
{
    Width = 100,
    Height = 100,
    CornerRadius = 5
};
var advancedQr = QRCodeWriter.CreateQrCodeWithLogo("Advanced Example", logo, 600);

// Production-ready branded QR code
public GeneratedBarcode CreateBrandedQrCode(string data, string logoPath, string brandColor)
{
    var logo = new QRCodeLogo(logoPath)
    {
        Width = 80,
        Height = 80,
        CornerRadius = 10
    };

    var qr = QRCodeWriter.CreateQrCodeWithLogo(data, logo, 800);
    qr.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml(brandColor));
    qr.SetMargins(15);
    return qr;
}
// Create QR code with embedded logo
var qrWithLogo = QRCodeWriter.CreateQrCodeWithLogo("Hello World", "logo.png", 500);
qrWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkRed);
qrWithLogo.SaveAsPng("Logo_QR_Code.png");

// Advanced logo customization
var logo = new QRCodeLogo("company-logo.png")
{
    Width = 100,
    Height = 100,
    CornerRadius = 5
};
var advancedQr = QRCodeWriter.CreateQrCodeWithLogo("Advanced Example", logo, 600);

// Production-ready branded QR code
public GeneratedBarcode CreateBrandedQrCode(string data, string logoPath, string brandColor)
{
    var logo = new QRCodeLogo(logoPath)
    {
        Width = 80,
        Height = 80,
        CornerRadius = 10
    };

    var qr = QRCodeWriter.CreateQrCodeWithLogo(data, logo, 800);
    qr.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml(brandColor));
    qr.SetMargins(15);
    return qr;
}
$vbLabelText   $csharpLabel

使用條碼自訂功能套用其他樣式。 條碼樣式功能提供完整的自訂選項:

// Use HTML color codes for brand colors
qrWithLogo.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#8B0000"));
qrWithLogo.ChangeBackgroundColor(System.Drawing.Color.LightGray);
qrWithLogo.AddAnnotationTextAboveBarcode("SCAN ME");
qrWithLogo.AddAnnotationTextBelowBarcode("Company Name");
// Use HTML color codes for brand colors
qrWithLogo.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#8B0000"));
qrWithLogo.ChangeBackgroundColor(System.Drawing.Color.LightGray);
qrWithLogo.AddAnnotationTextAboveBarcode("SCAN ME");
qrWithLogo.AddAnnotationTextBelowBarcode("Company Name");
$vbLabelText   $csharpLabel

有哪些匯出格式可供選擇?

儲存各種格式的二維碼,以適應不同的使用場景。 了解更多信息,請參閱保存條碼範例條碼圖像產生器教學。 對於特殊要求,請參閱建立 1-BPP 條碼影像的指南:

// Image formats
qrWithLogo.SaveAsJpeg("qr.jpg");
qrWithLogo.SaveAsPng("qr.png");
qrWithLogo.SaveAsGif("qr.gif");
qrWithLogo.SaveAsTiff("qr.tiff");

// Web formats
qrWithLogo.SaveAsHtmlFile("qr.html");
string dataUrl = qrWithLogo.ToDataUrl();

// Print formats
qrWithLogo.SaveAsPdf("qr.pdf");
qrWithLogo.ChangeBarcodeDpi(300);

// API formats
byte[] qrBytes = qrWithLogo.ToPngBinaryData();
var stream = qrWithLogo.ToStream();

// High-quality print export
public void ExportForPrint(GeneratedBarcode qr, string filename)
{
    qr.ChangeBarcodeDpi(600); // 高的 DPI for print
    qr.ResizeTo(2000, 2000); // Large size
    qr.SaveAsTiff(filename); // Lossless format
}
// Image formats
qrWithLogo.SaveAsJpeg("qr.jpg");
qrWithLogo.SaveAsPng("qr.png");
qrWithLogo.SaveAsGif("qr.gif");
qrWithLogo.SaveAsTiff("qr.tiff");

// Web formats
qrWithLogo.SaveAsHtmlFile("qr.html");
string dataUrl = qrWithLogo.ToDataUrl();

// Print formats
qrWithLogo.SaveAsPdf("qr.pdf");
qrWithLogo.ChangeBarcodeDpi(300);

// API formats
byte[] qrBytes = qrWithLogo.ToPngBinaryData();
var stream = qrWithLogo.ToStream();

// High-quality print export
public void ExportForPrint(GeneratedBarcode qr, string filename)
{
    qr.ChangeBarcodeDpi(600); // 高的 DPI for print
    qr.ResizeTo(2000, 2000); // Large size
    qr.SaveAsTiff(filename); // Lossless format
}
$vbLabelText   $csharpLabel

有關 PDF 的特定操作,請參閱有關在 PDF 中建立條碼在現有 PDF 上新增條碼的指南。 從 PDF 讀取條碼時,請使用PDF 條碼閱讀器設定以獲得最佳效果。

如何在Web應用程式中實作二維碼?

對於ASP.NET MVC 應用程序,實作無檔案 I/O 的串流。 該庫支援建立 HTML 條碼,以便直接整合到 Web 中:

public IActionResult GetQrCode(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 400);
    byte[] qrBytes = qr.ToPngBinaryData();
    return File(qrBytes, "image/png", "qrcode.png");
}

// Stream directly without disk I/O
public IActionResult StreamQrCode(string content)
{
    var qr = QRCodeWriter.CreateQrCode(content, 500);
    var stream = qr.ToStream();
    return File(stream, "image/png");
}

// Generate HTML-embedded QR codes
public IActionResult GetHtmlQrCode(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 400);
    var htmlString = qr.ToHtmlTag();
    return Content(htmlString, "text/html");
}
public IActionResult GetQrCode(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 400);
    byte[] qrBytes = qr.ToPngBinaryData();
    return File(qrBytes, "image/png", "qrcode.png");
}

// Stream directly without disk I/O
public IActionResult StreamQrCode(string content)
{
    var qr = QRCodeWriter.CreateQrCode(content, 500);
    var stream = qr.ToStream();
    return File(stream, "image/png");
}

// Generate HTML-embedded QR codes
public IActionResult GetHtmlQrCode(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 400);
    var htmlString = qr.ToHtmlTag();
    return Content(htmlString, "text/html");
}
$vbLabelText   $csharpLabel

對於Blazor應用,實現響應式二維碼生成:

@page "/qrcode"
@using IronBarCode

<input @bind="qrText" placeholder="Enter text" />
<button @onclick="GenerateQr">Generate</button>

@if (!string.IsNullOrEmpty(QrCodeDataUrl))
{
    <img src="@QrCodeDataUrl" alt="QR Code" />
}

@code {
    private string qrText = "";
    private string QrCodeDataUrl = "";

    private void GenerateQr()
    {
        if (!string.IsNullOrEmpty(qrText))
        {
            var qr = QRCodeWriter.CreateQrCode(qrText, 400);
            QrCodeDataUrl = qr.ToDataUrl();
        }
    }
}
@page "/qrcode"
@using IronBarCode

<input @bind="qrText" placeholder="Enter text" />
<button @onclick="GenerateQr">Generate</button>

@if (!string.IsNullOrEmpty(QrCodeDataUrl))
{
    <img src="@QrCodeDataUrl" alt="QR Code" />
}

@code {
    private string qrText = "";
    private string QrCodeDataUrl = "";

    private void GenerateQr()
    {
        if (!string.IsNullOrEmpty(qrText))
        {
            var qr = QRCodeWriter.CreateQrCode(qrText, 400);
            QrCodeDataUrl = qr.ToDataUrl();
        }
    }
}
$vbLabelText   $csharpLabel

若要將條碼匯出為 HTML,請參閱建立條碼為 HTML 指南。 在 Web 應用程式中套用許可證時,請參閱web.config 許可證金鑰指南

二維碼實施的最佳實務是什麼?

我該選擇哪一個糾錯等級?

糾錯能力會影響系統的韌性和容量。 有關詳細信息,請參閱糾錯指南。 該庫包含機器學習置信度閾值,以提高準確率:

等級 恢復 用例
低的 7% 清潔的數位環境
中等的 15% 印刷材料、名片
高的 25% 戶外標誌、手拿物品
最高 30% 工業用途,添加標識

我的二維碼應該有多大?

根據掃描距離計算最佳尺寸。 了解如何設定邊距以提高掃描效果。 以下邊距設定範例展示了最佳實務:

// 1:10 ratio - 1cm QR per 10cm distance
int CalculateQrSize(double scanDistanceMeters)
{
    int sizeInCm = (int)(scanDistanceMeters * 10);
    return (int)(sizeInCm * 37.8); // Convert to pixels at 96 DPI
}

// Set appropriate margins for reliable scanning
public GeneratedBarcode CreateScanOptimizedQr(string data, int scanDistance)
{
    int size = CalculateQrSize(scanDistance);
    var qr = QRCodeWriter.CreateQrCode(data, size);
    qr.SetMargins(size / 20); // 5% margin
    return qr;
}
// 1:10 ratio - 1cm QR per 10cm distance
int CalculateQrSize(double scanDistanceMeters)
{
    int sizeInCm = (int)(scanDistanceMeters * 10);
    return (int)(sizeInCm * 37.8); // Convert to pixels at 96 DPI
}

// Set appropriate margins for reliable scanning
public GeneratedBarcode CreateScanOptimizedQr(string data, int scanDistance)
{
    int size = CalculateQrSize(scanDistance);
    var qr = QRCodeWriter.CreateQrCode(data, size);
    qr.SetMargins(size / 20); // 5% margin
    return qr;
}
$vbLabelText   $csharpLabel

如何確保行動裝置相容性?

透過條碼閱讀器設定改進行動掃描。 如果遇到識別問題,請參閱條碼無法識別故障排除指南

public GeneratedBarcode CreateMobileOptimizedQr(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 800, QRCodeWriter.QrErrorCorrectionLevel.Medium);
    qr.SetMargins(20); // Adequate quiet zone
    qr.ChangeBarCodeColor(System.Drawing.Color.Black);
    qr.ChangeBackgroundColor(System.Drawing.Color.White);
    return qr;
}
public GeneratedBarcode CreateMobileOptimizedQr(string data)
{
    var qr = QRCodeWriter.CreateQrCode(data, 800, QRCodeWriter.QrErrorCorrectionLevel.Medium);
    qr.SetMargins(20); // Adequate quiet zone
    qr.ChangeBarCodeColor(System.Drawing.Color.Black);
    qr.ChangeBackgroundColor(System.Drawing.Color.White);
    return qr;
}
$vbLabelText   $csharpLabel

對於跨平台行動開發,請探索.NET MAUI條碼掃描器教學。 該函式庫原生支援iOSAndroid平台。 ## 常見整合場景

建立行銷活動二維碼

若要實現具有自訂品牌標識的可追蹤行銷二維碼,請參閱條碼讀取速度管理指南

public GeneratedBarcode CreateCampaignQr(string campaignId, string userId)
{
    string trackingUrl = "___PROTECTED_URL_79___";
    var qr = QRCodeWriter.CreateQrCodeWithLogo(trackingUrl, "logo.png", 1000);
    qr.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#1E3A8A"));
    qr.AddAnnotationTextAboveBarcode($"Campaign: {campaignId}");
    return qr;
}

// Batch generate campaign materials
public async Task GenerateCampaignBatch(List<string> userIds, string campaignId)
{
    var tasks = userIds.Select(async userId =>
    {
        var qr = CreateCampaignQr(campaignId, userId);
        await Task.Run(() => qr.SaveAsPng($"campaigns/{campaignId}/{userId}.png"));
    });

    await Task.WhenAll(tasks);
}
public GeneratedBarcode CreateCampaignQr(string campaignId, string userId)
{
    string trackingUrl = "___PROTECTED_URL_79___";
    var qr = QRCodeWriter.CreateQrCodeWithLogo(trackingUrl, "logo.png", 1000);
    qr.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml("#1E3A8A"));
    qr.AddAnnotationTextAboveBarcode($"Campaign: {campaignId}");
    return qr;
}

// Batch generate campaign materials
public async Task GenerateCampaignBatch(List<string> userIds, string campaignId)
{
    var tasks = userIds.Select(async userId =>
    {
        var qr = CreateCampaignQr(campaignId, userId);
        await Task.Run(() => qr.SaveAsPng($"campaigns/{campaignId}/{userId}.png"));
    });

    await Task.WhenAll(tasks);
}
$vbLabelText   $csharpLabel

產生產品標籤二維碼

建立用於庫存管理的二維碼。 有關處理特殊格式的信息,請參閱GS1-128 故障排除指南。 使用特定類型的條碼(例如Code 39MSI 條碼)時,請參考特定格式的指南:

public void GenerateProductLabel(Product product)
{
    var productData = new
    {
        sku = product.SKU,
        batch = product.BatchNumber,
        expiry = product.ExpiryDate.ToString("yyyy-MM-dd")
    };

    string json = System.Text.Json.JsonSerializer.Serialize(productData);
    var qr = QRCodeWriter.CreateQrCode(json, 400, QRCodeWriter.QrErrorCorrectionLevel.High);
    qr.AddAnnotationTextAboveBarcode(product.Name);
    qr.SaveAsPng($"labels/product-{product.SKU}.png");
}

// Generate 1-BPP labels for thermal printers
public void GenerateThermalLabel(Product product)
{
    var qr = CreateProductQr(product);
    qr.SaveAs1BitPerPixelPng($"thermal/{product.SKU}.png");
}
public void GenerateProductLabel(Product product)
{
    var productData = new
    {
        sku = product.SKU,
        batch = product.BatchNumber,
        expiry = product.ExpiryDate.ToString("yyyy-MM-dd")
    };

    string json = System.Text.Json.JsonSerializer.Serialize(productData);
    var qr = QRCodeWriter.CreateQrCode(json, 400, QRCodeWriter.QrErrorCorrectionLevel.High);
    qr.AddAnnotationTextAboveBarcode(product.Name);
    qr.SaveAsPng($"labels/product-{product.SKU}.png");
}

// Generate 1-BPP labels for thermal printers
public void GenerateThermalLabel(Product product)
{
    var qr = CreateProductQr(product);
    qr.SaveAs1BitPerPixelPng($"thermal/{product.SKU}.png");
}
$vbLabelText   $csharpLabel

對於特殊標籤列印,請查看1-BPP 條碼圖像指南。 閱讀多頁文件時,請參閱多頁 GIF 和 TIFF 指南

提高條碼掃描效能

對於大批量掃描應用,實施作物區域以限制掃描區域並提高效能。 讀取速度選項可對精度和速度之間的權衡進行精細控制:

// Define crop region for faster scanning
var cropRegion = new Rectangle(100, 100, 300, 300);
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Faster,
    ExpectBarcodeTypes = BarcodeEncoding.QRCode,
    CropArea = cropRegion
};

var results = BarcodeReader.Read("image.png", options);
// Define crop region for faster scanning
var cropRegion = new Rectangle(100, 100, 300, 300);
var options = new BarcodeReaderOptions
{
    Speed = ReadingSpeed.Faster,
    ExpectBarcodeTypes = BarcodeEncoding.QRCode,
    CropArea = cropRegion
};

var results = BarcodeReader.Read("image.png", options);
$vbLabelText   $csharpLabel

在使用System.Drawing 物件時,該程式庫透過 IronDrawing 提供跨平台相容性。

重點總結

IronBarcode為.NET應用程式提供完整的二維碼產生解決方案。 該程式庫提供直覺的 API、豐富的文件和可用於生產環境的功能,包括容錯性跨平台支援效能最佳化。 透過更新日誌了解最新功能。 對於注重安全性的部署,請查看安全 CVE 揭露資訊

請在許可頁面上尋找許可資訊。 IronBarcode提供免費的開發者許可證,並提供包含支援和更新在內的進階選項。 對於現有客戶,請了解許可證延期升級選項。 如果您需要有關許可方面的協助,請參閱許可證金鑰申請指南web.config 許可設定

對於生產環境部署,請參考AWS LambdaAzure FunctionsDocker 容器的相關指南。 若要檢視特定的部署問題,請參閱AWS Lambda 執行時間指南執行階段複製異常解決方案。 若遇到誤報,請查閱詳細的故障排除指南。

如需技術支持,請提交工程請求。 該程式庫會定期進行更新,如產品更新部分所示,以確保持續的兼容性和新功能。

快速入門二維碼範例

只需幾行程式碼即可產生具有自訂樣式的二維碼。 如需更多範例,請造訪建立條碼範例,並探索讀取條碼教學課程,以取得完整的條碼解決方案。 其他範例包括從 PDF 讀取條碼從資料建立條碼

using IronBarCode;

// Create QR code with custom size and error correction
var qrCode = QRCodeWriter.CreateQrCode("___PROTECTED_URL_81___", 500, QRCodeWriter.QrErrorCorrectionLevel.High);

// Add styling
qrCode.ChangeBarCodeColor(System.Drawing.Color.Navy);
qrCode.AddBarcodeValueTextBelowBarcode();

// Save as image
qrCode.SaveAsPng("quickstart-qr.png");

// Export for API
byte[] pngBytes = qrCode.ToPngBinaryData();
using IronBarCode;

// Create QR code with custom size and error correction
var qrCode = QRCodeWriter.CreateQrCode("___PROTECTED_URL_81___", 500, QRCodeWriter.QrErrorCorrectionLevel.High);

// Add styling
qrCode.ChangeBarCodeColor(System.Drawing.Color.Navy);
qrCode.AddBarcodeValueTextBelowBarcode();

// Save as image
qrCode.SaveAsPng("quickstart-qr.png");

// Export for API
byte[] pngBytes = qrCode.ToPngBinaryData();
$vbLabelText   $csharpLabel

IronBarcode支援透過.NET MAUIAWS LambdaAzureDocker和行動平台上部署。 如需技術支持,請提交工程請求。 查看安全漏洞 CVE 揭露訊息,以滿足企業安全要求。

探索條碼讀取功能,了解條碼辨識的全部功能,包括支援讀取 Code 39 條碼和其他特殊格式。 此程式庫功能齊全,適用於需要可靠的條碼產生和掃描功能的企業應用程式。

常見問題解答

如何在 .NET 應用程式中生成 QR 碼?

在 .NET 應用程式中,您可以使用 IronBarcode 中的 QRCodeWriter.CreateQrCode 方法生成 QR 碼。此方法允許您指定 QR 碼的數據、大小和糾錯級別。

QR 碼有哪些自定義選項?

IronBarcode 允許 QR 碼的自定義,包括更改顏色和嵌入圖片如公司標誌。這些功能增強了 QR 碼的視覺吸引力和品牌整合。

如何在我的項目中安裝 IronBarcode 庫?

您可以通過 Visual Studio 的 NuGet 包管理器 UI、包管理器控制台或從 NuGet 網站下載來在項目中安裝 IronBarcode。

IronBarcode可以用來從視頻幀中讀取條碼嗎?

是的,IronBarcode 可以處理視頻幀,允許其通過校正旋轉和噪聲實現實時條碼讀取,從而提高了條碼讀取效率。

用 IronBarcode 生成的 QR 碼可以保存為哪些文件格式?

用 IronBarcode 生成的 QR 碼可以保存為多種格式,包括 PNG 和 HTML,為不同應用需求提供靈活性。

IronBarcode 是否適用於控制台和網路應用程式?

是的,IronBarcode 多才多藝,可以用於控制台和 .NET MVC 網路應用程式,使其成為多種開發環境的穩健選擇。

IronBarcode 中可用的 QR 碼糾錯級別有哪些?

IronBarcode 支持用於 QR 碼的四個糾錯級別:低、中、高和最高,確保即使 QR 碼受損也能保持數據完整性。

IronBarcode 的許可選項有哪些?

IronBarcode 提供免費的開發者許可和包含額外支持和更新的高級版本,滿足不同的開發和商業需求。

IronBarcode 是否兼容 .NET Core 和 .NET Framework?

是的,IronBarcode 兼容 .NET Core 和 .NET Framework,支持包括 32 位和 64 位系統的多種架構。

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担產品测测试,產品開發和研究的责任時,Jordi 為持续的產品改進增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me