我可以在Azure上使用 .NET 運行 IronBarcode 嗎?
可以! IronBarcode 可用於讀取和寫入託管於Azure服務上的 .NET 應用程式中的 QR/條碼。 IronBarcode 已在多個Azure平台上進行了全面測試,包括MVC網站、Azure Functions等更多。
先決條件
1. 安裝 IronBarcode 以開始使用
首先,在NuGet網站上安裝 NuGet 套件。
作為替代,也可以下載 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;
}
}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)> req As HttpRequest,
log As ILogger) As HttpResponseMessage
log.LogInformation("VB.NET 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在此程式碼中:
- 我們定義了一個名為 "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回應中。
Is it necessary to set a license key for using IronBarcode in Azure Functions?
Yes, setting a license key for IronBarcode is necessary in Azure Functions to activate the library and remove any limitations.
What file format is used for barcodes generated by IronBarcode in Azure Functions?
Barcodes generated by IronBarcode in Azure Functions are converted to JPEG format for the HTTP response.
How are content headers set for barcode images in Azure Functions using IronBarcode?
Content headers are set to define the barcode image as a downloadable attachment with the current date and time as part of the file name.

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。