我可以在 Azure 上使用 .NET 运行 IronBarcode 吗?
是的! 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上使用Docker是获得对IronBarcode性能和稳定性控制能力的一种方法。 要了解如何在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在此代码中:
- 我们定义一个名为"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,当通过 HTTP 请求触发时,使用 IronBarcode 生成 QR 码。它记录一条消息、设置许可证密钥、使用 BarcodeWriter.CreateBarcode 创建 QR 码,并在 HTTP 响应中以 JPEG 文件返回图像。
在 Azure Function 中创建 QR 码需要哪些代码?
在 Azure Function 中,使用 IronBarcode 通过调用 BarcodeWriter.CreateBarcode 创建 QR 码。生成的 QR 码可以作为 HTTP 响应中的 JPEG 图像返回。






