我可以在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

作為替代,也可以下載 IronBarcode.dll並新增到您的專案中。


如何操作教學

2. 效能與Azure層級

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

3. 框架選擇

.NET Standard、Core 和 Framework 專案都與 IronBarcode 相容。

4. 在 Azure 上使用 Docker

在Azure上使用IronBarcode來控制性能和穩定性的一種方法是使用Docker。 要學習如何將 IronBarcode 與 Azure 和 Docker 結合,請查看此教學

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碼條碼。
  • 條碼圖像被轉換為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可以設置為在使用IronBarcode的HTTP請求觸發時生成QR碼。它記錄消息、設置授權金鑰、使用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大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備好開始了嗎?
Nuget 下載 2,317,217 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在滾動嗎?

想快速驗證嗎? PM > Install-Package BarCode
運行範例觀看您的字串成為條碼。