我可以在 Azure 上使用 .NET 執行 IronBarcode 嗎?

This article was translated from English: Does it need improvement?
Translated
View the article in English

沒問題! IronBarcode 可用於在託管於 Azure 服務上的 .NET 應用程式中讀取和寫入 QR 碼/條碼。 IronBarcode 已在多個 Azure 平台上經過徹底測試,包括 MVC 網站、Azure Functions 以及更多平台。


先決條件

1. 安裝 IronBarcode 以開始使用

首先,請在 NuGet 網站上安裝此 NuGet 套件。

Install-Package BarCode

As an alternative, the IronBarcode.dll could also be downloaded and added to your project.


操作教學

2. 效能與 Azure 服務層級

我們建議至少使用 Azure B1 服務方案,因其適用於多數使用者的使用情境。 需要更高吞吐量的系統將需要更高階的服務方案。

3. 框架選擇

.NET Standard、Core 及 Framework 專案皆與 IronBarcode 相容。

4. Azure 上的 Docker

在 Azure 上使用 IronBarcode 來掌控效能與穩定性的方法之一,就是採用 Docker。 若要了解如何在 Azure 和 Docker 上使用 IronBarcode,請參閱此教學指南

5. 官方 Azure Function 支援

IronBarcode 目前支援 Azure Functions V3 和 V4。

Azure Function 實作程式碼範例

已於 Azure Functions v3.3.1.0 以上版本進行測試。 以下為程式碼範例:

using System;
using System.Net;
using System.Net.Http;
using IronBarCode;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;

public static class BarcodeFunction
{
    // Azure Function triggered by HTTP request.
    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // Set the license key for IronBarcode if needed.
        IronBarCode.License.LicenseKey = "Key";

        // Create a QR barcode from a string.
        var myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode);

        // Prepare the HTTP response to return the barcode image.
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(myBarCode.ToJpegBinaryData())
        };

        // Set content headers for attachment and content type.
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        { 
            FileName = $"{DateTime.Now:yyyyMMddmm}.jpg" 
        };

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

        return response;
    }
}
using System;
using System.Net;
using System.Net.Http;
using IronBarCode;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;

public static class BarcodeFunction
{
    // Azure Function triggered by HTTP request.
    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // Set the license key for IronBarcode if needed.
        IronBarCode.License.LicenseKey = "Key";

        // Create a QR barcode from a string.
        var myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode);

        // Prepare the HTTP response to return the barcode image.
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(myBarCode.ToJpegBinaryData())
        };

        // Set content headers for attachment and content type.
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        { 
            FileName = $"{DateTime.Now:yyyyMMddmm}.jpg" 
        };

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

        return response;
    }
}
Imports System
Imports System.Net
Imports System.Net.Http
Imports IronBarCode
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.Extensions.Logging
Imports System.Net.Http.Headers

Public Module BarcodeFunction
	' Azure Function triggered by HTTP request.
	<FunctionName("barcode")>
	Public Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger) As HttpResponseMessage
		log.LogInformation("C# HTTP trigger function processed a request.")

		' Set the license key for IronBarcode if needed.
		IronBarCode.License.LicenseKey = "Key"

		' Create a QR barcode from a string.
		Dim myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode)

		' Prepare the HTTP response to return the barcode image.
		Dim response = New HttpResponseMessage(HttpStatusCode.OK) With {.Content = New ByteArrayContent(myBarCode.ToJpegBinaryData())}

		' Set content headers for attachment and content type.
		response.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"{DateTime.Now:yyyyMMddmm}.jpg"}

		response.Content.Headers.ContentType = New MediaTypeHeaderValue("image/jpeg")

		Return response
	End Function
End Module
$vbLabelText   $csharpLabel

在此程式碼中:

  • 我們定義了一個名為"BARCODE"的 Azure Function。
  • 此函式由 HTTP 請求觸發,並在處理完成時記錄一則訊息。
  • 我們在此指定 IronBarcode 的授權金鑰(請將 "Key" 替換為您的實際授權金鑰)。
  • 透過 BarcodeWriter.CreateBarcode 產生 QR BARCODE。
  • BarCode 圖像將轉換為 JPEG 格式,並包含在 HTTP 回應中。
  • 回覆內容設定為可下載的附件,檔案名稱採用當前日期與時間。
  • 回應內容類型設定為"image/jpeg",以標示圖片格式。

常見問題

如何將條碼功能整合到我的Azure應用程式中?

您可以使用IronBarcode將條碼功能整合到您的Azure應用程式中。首先通過命令行安裝IronBarcode NuGet包,或下載IronBarcode.dll並添加到您的專案中。

哪些Azure服務計劃適合條碼處理?

對於大多數使用案例,使用IronBarcode時建議使用Azure B1服務計劃。如果您的應用程式需要更高的吞吐量,考慮升級到更高的服務計劃。

IronBarcode是否與Azure的所有.NET框架兼容?

是的,IronBarcode與.NET Standard、Core和Framework專案兼容,在Azure上部署應用程式時具備靈活性。

我可以使用Docker提高Azure上條碼處理性能嗎?

是的,您可以使用Docker增強Azure上條碼處理的性能和穩定性。提供有關將IronBarcode與Docker整合的詳細教程。

IronBarcode庫是否支持Azure Functions?

IronBarcode支持Azure Functions V3和V4。它允許在無伺服器環境中無縫整合條碼處理。

Azure Function如何使用IronBarcode處理條碼?

可以設置Azure Function,以便在HTTP請求觸發時生成QR碼,使用IronBarcode記錄消息,設置授權金鑰,使用BarcodeWriter.CreateBarcode創建QR碼,並將圖像作為JPEG文件返回在HTTP響應中。

在Azure Function中需要哪些代碼來創建QR碼?

在Azure Function中,使用IronBarcode通過調用BarcodeWriter.CreateBarcode來創建QR碼。然後可以將生成的QR碼作為JPEG圖像返回在HTTP響應中。

IronBarcode可以處理1D和2D條碼嗎?

IronBarcode能夠處理1D和2D條碼,支援從簡單產品標籤到複雜數據編碼的廣泛應用。

IronBarcode的商業用途有授權選項嗎?

Iron Software為IronBarcode提供各種授權選項,包括針對企業級應用的商業授權,確保符合業務需求。

IronBarcode支援批次處理條碼嗎?

是的,IronBarcode支援批次處理,允許開發者在一次操作中生成或讀取多個條碼,提升大規模應用的效率。

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備好開始了嗎?
Nuget 下載 2,240,258 | 版本: 2026.5 just released
Still Scrolling Icon

還在捲動嗎?

想要快速證明? PM > Install-Package BarCode
執行範例 看您的字串變成 BarCode。