从LEADTOOLS条形码迁移到IronBarcode
本指南涵盖了.NET开发人员从LEADTOOLS条形码 到IronBarcode的完整迁移过程。 它解决了移除LEADTOOLS NuGet包和一个本地运行时依赖项的问题,用字符串密钥替代了基于文件的LEADTOOLS许可初始化序列,并将LEADTOOLS读取和写入模式转换为IronBarcode的静态流畅API。 针对每个主要迁移场景,我们提供了代码示例,以及 API 映射表、结构化清单和过渡期间出现的问题的指导。
为什么要从LEADTOOLS条形码迁移?
**基于文件的许可证部署:**LEADTOOLS许可要求 .LIC 文件在每个运行应用程序的机器上,以已知路径物理存在于磁盘上。 开发人员工作站、CI 构建代理、预发布服务器和生产容器都需要在应用程序初始化之前配置该文件。这与基于字符串的密钥有着本质区别,后者可以很好地集成到环境变量、密钥管理器和 CI/CD 流水线配置中。 部署拓扑中添加的每个新环境(例如新的云区域、新的 Kubernetes 节点池、新的开发人员入职)都需要一个基于字符串的许可不需要的文件配置步骤。
**SDK 占用空间:**LEADTOOLS条码安装需要 Leadtools.Barcode NuGet 包(这会引入 Leadtools.Codecs 和相关依赖项)。 PDF 条码提取添加了 Leadtools.Pdf。 在 Windows 系统上,MSVC++ 2017 运行时是一个单独的本地依赖项。LEADTOOLS条形码应用程序的发布输出大小约为 148 MB。 只需要读取或生成条形码的应用,无论是否使用这些功能,都承载着完整的成像平台的全部功能——OCR 基础架构、格式编解码器架构和文档查看功能。
**传统 API 设计:**LEADTOOLS条形码操作需要按特定顺序构建多个对象,然后才能进行任何操作。 读取条码需要一个 RasterCodecs 实例加载图像,并使用一个 BarcodeEngine 实例进行扫描,带有一个显式的 BarcodeSymbology 数组声明要查找的格式。 生成条码需要构建一个 BarcodeData 对象,创建一个带有显式像素参数的空白 RasterImage,使用 FillCommand 填充背景色,将条码写入其中,然后使用 RasterCodecs 保存。 该API反映了其时代的设计模式。 IronBarcode通过直接接受文件路径的静态方法调用来执行相同的操作。
定价透明度: LEADTOOLS生产服务器部署许可证通过LEADTOOLS销售单独报价,而不会在其网站上公布。需要在开始开发前获得完整成本信息的团队必须在确认LEADTOOLS符合其预算之前与销售接洽。 IronBarcode提供永久性一次性许可证,涵盖开发和部署,无需单独的生产许可证。
基本问题
LEADTOOLS 初始化顺序需要20多行代码和四个验证步骤才能创建一个 BarcodeEngine。 IronBarcode将整个序列替换为单个赋值:
// LEADTOOLS: file path, expiry check, three feature lock checks, engine creation
using Leadtools;
using Leadtools.Barcode;
RasterSupport.SetLicense(
@"C:\LEADTOOLS23\Support\Common\License\LEADTOOLS.LIC",
"your-developer-key-here");
if (RasterSupport.KernelExpired)
throw new InvalidOperationException("LEADTOOLS license has expired");
if (RasterSupport.IsLocked(RasterSupportType.Barcode1DRead))
throw new InvalidOperationException("1D barcode reading is locked");
if (RasterSupport.IsLocked(RasterSupportType.Barcode2DRead))
throw new InvalidOperationException("2D barcode reading is locked");
if (RasterSupport.IsLocked(RasterSupportType.BarcodeWrite))
throw new InvalidOperationException("Barcode writing is locked");
var engine = new BarcodeEngine();Imports Leadtools
Imports Leadtools.Barcode
' LEADTOOLS: file path, expiry check, three feature lock checks, engine creation
RasterSupport.SetLicense("C:\LEADTOOLS23\Support\Common\License\LEADTOOLS.LIC", "your-developer-key-here")
If RasterSupport.KernelExpired Then
Throw New InvalidOperationException("LEADTOOLS license has expired")
End If
If RasterSupport.IsLocked(RasterSupportType.Barcode1DRead) Then
Throw New InvalidOperationException("1D barcode reading is locked")
End If
If RasterSupport.IsLocked(RasterSupportType.Barcode2DRead) Then
Throw New InvalidOperationException("2D barcode reading is locked")
End If
If RasterSupport.IsLocked(RasterSupportType.BarcodeWrite) Then
Throw New InvalidOperationException("Barcode writing is locked")
End If
Dim engine As New BarcodeEngine()// IronBarcode: one line, no file required
using IronBarCode;
IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE");Imports IronBarCode
IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE")IronBarcode与LEADTOOLS条码:功能对比
| 特征 | LEADTOOLS条形码 | IronBarcode |
|---|---|---|
| 许可模式 | 文件 + 开发者密钥 | 仅字符串键 |
| 需要NuGet包 | 5岁以上 | 1 |
| 原生运行时依赖项 | MSVC++ 2017(Windows) | None |
| 发布输出大小 | 约 148 MB | 约 39 MB |
| 支持的符号系统总数 | 40岁以上 | 50岁以上 |
| 自动检测条形码格式 | 有限的 | 是 |
| PDF条形码提取 | 需要单独的包装 | 内置 |
| 机器学习误差校正 | 否 | 是 |
| 二维码标志品牌推广 | 否 | 是 |
| Docker部署 | 文件挂载要求 | 环境变量 |
| 初始化代码 | 20行以上 | 1 行 |
| API 风格 | 遗留对象图 | 静态流畅 |
| 跨平台 | 部分(原生依赖项) | 完整版(.NET Standard) |
| 部署许可定价 | 联系销售(未公开) | 包含在永久购买权中 |
快速入门:LEADTOOLS 条码到IronBarcode 的迁移
步骤 1:移除LEADTOOLS软件包
从项目中移除所有LEADTOOLS包:
dotnet remove package Leadtools.Barcode
dotnet remove package Leadtools
dotnet remove package Leadtools.Codecs
dotnet remove package Leadtools.Codecs.Png
dotnet remove package Leadtools.Codecs.Jpeg
如果添加了用于从 PDF 文件中提取条形码的 PDF 编解码器:
dotnet remove package Leadtools.Pdf
在 Windows Server 部署中,迁移完成后可以从配置脚本中删除 MSVC++ 2017 运行时。 IronBarcode在任何平台上都没有原生运行时依赖项。
步骤 2:安装IronBarcode
dotnet add package IronBarcode
该单一软件包包含所有图像格式支持、原生 PDF 条形码提取、ML 纠错以及所有 50 多种支持的符号体系。 无需额外安装解码器包。
步骤 3:初始化许可证
用一行代码替换整个LEADTOOLS初始化块。 在代码库中找到每个对 RasterSupport.SetLicense 的调用 —— 通常只有一个,在应用程序启动时 —— 并替换整个周围的初始化顺序:
// Before: entireLEADTOOLSinitialization block (20+ lines)
// After:
using IronBarCode;
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
许可证密钥可以从任何支持字符串的配置机制中获取:环境变量、appsettings.json、Azure 密钥库、AWS Secrets Manager 或 Kubernetes secret。 有关基于环境的许可证配置、Docker 部署模式以及所有支持的配置方法,请参阅许可证密钥设置文档。
代码迁移示例
从图像中读取条形码
LEADTOOLS 将图像加载和条形码扫描分离成两个不同的对象层。 一个 RasterCodecs 实例将图像文件加载到 RasterImage 中,一个 BarcodeEngine 实例进行扫描。 调用者还必须提供一个显式的 BarcodeSymbology 值数组; 数组中未列出的格式将无法检测到。
LEADTOOLS 方法:
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
using var codecs = new RasterCodecs();
using var image = codecs.Load("scan.png");
var engine = new BarcodeEngine();
var symbologies = new[]
{
BarcodeSymbology.Code128,
BarcodeSymbology.Code39,
BarcodeSymbology.QR,
BarcodeSymbology.DataMatrix,
BarcodeSymbology.EAN13,
BarcodeSymbology.UPCA
};
var barcodes = engine.Reader.ReadBarcodes(
image,
LogicalRectangle.Empty,
0,
symbologies);
foreach (var barcode in barcodes)
Console.WriteLine($"{barcode.Symbology}: {barcode.Value}");Imports Leadtools
Imports Leadtools.Barcode
Imports Leadtools.Codecs
Dim codecs As New RasterCodecs()
Using codecs
Dim image = codecs.Load("scan.png")
Using image
Dim engine As New BarcodeEngine()
Dim symbologies = New BarcodeSymbology() {
BarcodeSymbology.Code128,
BarcodeSymbology.Code39,
BarcodeSymbology.QR,
BarcodeSymbology.DataMatrix,
BarcodeSymbology.EAN13,
BarcodeSymbology.UPCA
}
Dim barcodes = engine.Reader.ReadBarcodes(
image,
LogicalRectangle.Empty,
0,
symbologies)
For Each barcode In barcodes
Console.WriteLine($"{barcode.Symbology}: {barcode.Value}")
Next
End Using
End UsingIronBarcode方法:
using IronBarCode;
var results = BarcodeReader.Read("scan.png");
foreach (var result in results)
Console.WriteLine($"{result.Format}: {result.Value}");Imports IronBarCode
Dim results = BarcodeReader.Read("scan.png")
For Each result In results
Console.WriteLine($"{result.Format}: {result.Value}")
NextIronBarcode直接接受文件路径,在内部加载图像,并自动检测所有 50 多种受支持的条码格式,无需调用者列举预期类型。有关高级配置(例如读取速度调整、多条码检测和低质量图像处理),请参阅"从图像读取条码"指南。
生成 Code 128 条形码
LEADTOOLS 生成需要构建一个 BarcodeData 对象,分配一个带有显式内存标志、像素深度和字节序列的空白 RasterImage,填充背景色,将条码写入其中,然后使用 RasterCodecs 保存。 IronBarcode通过一条流畅的方法链执行所有这些步骤。
LEADTOOLS 方法:
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
var engine = new BarcodeEngine();
var barcodeData = new BarcodeData()
{
Symbology = BarcodeSymbology.Code128,
Value = "ITEM-98765",
Bounds = new LeadRect(0, 0, 500, 120)
};
using var image = new RasterImage(
RasterMemoryFlags.Conventional,
500, 120, 24,
RasterByteOrder.Bgr,
RasterViewPerspective.TopLeft,
null, IntPtr.Zero, 0);
new FillCommand(RasterColor.White).Run(image);
engine.Writer.WriteBarcode(image, barcodeData, null);
using var codecs = new RasterCodecs();
codecs.Save(image, "item-barcode.png", RasterImageFormat.Png, 0);Imports Leadtools
Imports Leadtools.Barcode
Imports Leadtools.Codecs
Dim engine As New BarcodeEngine()
Dim barcodeData As New BarcodeData() With {
.Symbology = BarcodeSymbology.Code128,
.Value = "ITEM-98765",
.Bounds = New LeadRect(0, 0, 500, 120)
}
Using image As New RasterImage(
RasterMemoryFlags.Conventional,
500, 120, 24,
RasterByteOrder.Bgr,
RasterViewPerspective.TopLeft,
Nothing, IntPtr.Zero, 0)
Dim fillCommand As New FillCommand(RasterColor.White)
fillCommand.Run(image)
engine.Writer.WriteBarcode(image, barcodeData, Nothing)
Using codecs As New RasterCodecs()
codecs.Save(image, "item-barcode.png", RasterImageFormat.Png, 0)
End Using
End UsingIronBarcode方法:
using IronBarCode;
BarcodeWriter.CreateBarcode("ITEM-98765", BarcodeEncoding.Code128)
.ResizeTo(500, 120)
.SaveAsPng("item-barcode.png");Imports IronBarCode
BarcodeWriter.CreateBarcode("ITEM-98765", BarcodeEncoding.Code128) _
.ResizeTo(500, 120) _
.SaveAsPng("item-barcode.png")有关尺寸、样式、边距控制和支持的输出格式的完整说明,请参阅创建条形码图像。
生成带有品牌标识的二维码
LEADTOOLS QR 码生成遵循与其他条码类型相同的多步骤 RasterImage 构建模式。IronBarcode提供 QRCodeWriter,具有嵌入 QR 码中心 LOGO 的专用 AddBrandLogo 方法。
LEADTOOLS 方法:
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
var engine = new BarcodeEngine();
var qrData = new BarcodeData()
{
Symbology = BarcodeSymbology.QR,
Value = "https://example.com/product/12345",
Bounds = new LeadRect(0, 0, 400, 400)
};
using var image = new RasterImage(
RasterMemoryFlags.Conventional,
400, 400, 24,
RasterByteOrder.Bgr,
RasterViewPerspective.TopLeft,
null, IntPtr.Zero, 0);
new FillCommand(RasterColor.White).Run(image);
engine.Writer.WriteBarcode(image, qrData, null);
using var codecs = new RasterCodecs();
codecs.Save(image, "product-qr.png", RasterImageFormat.Png, 0);Imports Leadtools
Imports Leadtools.Barcode
Imports Leadtools.Codecs
Dim engine As New BarcodeEngine()
Dim qrData As New BarcodeData() With {
.Symbology = BarcodeSymbology.QR,
.Value = "https://example.com/product/12345",
.Bounds = New LeadRect(0, 0, 400, 400)
}
Using image As New RasterImage(
RasterMemoryFlags.Conventional,
400, 400, 24,
RasterByteOrder.Bgr,
RasterViewPerspective.TopLeft,
Nothing, IntPtr.Zero, 0)
Dim fillCommand As New FillCommand(RasterColor.White)
fillCommand.Run(image)
engine.Writer.WriteBarcode(image, qrData, Nothing)
Using codecs As New RasterCodecs()
codecs.Save(image, "product-qr.png", RasterImageFormat.Png, 0)
End Using
End UsingIronBarcode方法:
using IronBarCode;
QRCodeWriter.CreateQrCode("https://example.com/product/12345", 400, QRCodeWriter.QrErrorCorrectionLevel.Highest)
.AddBrandLogo("brand-logo.png")
.SaveAsPng("product-qr.png");Imports IronBarCode
QRCodeWriter.CreateQrCode("https://example.com/product/12345", 400, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.AddBrandLogo("brand-logo.png") _
.SaveAsPng("product-qr.png")从PDF文档中提取条形码
LEADTOOLS PDF 条码提取需要单独的 Leadtools.Pdf 包、显式 PDF 加载配置、手动页数查询和对每页的循环。 每个页面在扫描之前必须单独加载为 RasterImage。IronBarcode的基础软件包中包含 PDF 支持,并在内部处理页面迭代。
LEADTOOLS 方法:
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
// Requires: dotnet add package Leadtools.Pdf
using var codecs = new RasterCodecs();
codecs.Options.Pdf.Load.Resolution = 300;
codecs.Options.Pdf.Load.DisplayDepth = 24;
var engine = new BarcodeEngine();
var results = new List<string>();
int pageCount = codecs.GetTotalPages("shipment.pdf");
for (int page = 1; page <= pageCount; page++)
{
using var image = codecs.Load(
"shipment.pdf", 0,
CodecsLoadByteOrder.BgrOrGray,
page, page);
var barcodes = engine.Reader.ReadBarcodes(
image, LogicalRectangle.Empty, 0, null);
foreach (var barcode in barcodes)
results.Add($"Page {page}: {barcode.Value}");
}Imports Leadtools
Imports Leadtools.Barcode
Imports Leadtools.Codecs
' Requires: dotnet add package Leadtools.Pdf
Using codecs As New RasterCodecs()
codecs.Options.Pdf.Load.Resolution = 300
codecs.Options.Pdf.Load.DisplayDepth = 24
Dim engine As New BarcodeEngine()
Dim results As New List(Of String)()
Dim pageCount As Integer = codecs.GetTotalPages("shipment.pdf")
For page As Integer = 1 To pageCount
Using image = codecs.Load("shipment.pdf", 0, CodecsLoadByteOrder.BgrOrGray, page, page)
Dim barcodes = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing)
For Each barcode In barcodes
results.Add($"Page {page}: {barcode.Value}")
Next
End Using
Next
End UsingIronBarcode方法:
using IronBarCode;
var results = BarcodeReader.Read("shipment.pdf");
foreach (var result in results)
Console.WriteLine($"Page {result.PageNumber}: {result.Value}");Imports IronBarCode
Dim results = BarcodeReader.Read("shipment.pdf")
For Each result In results
Console.WriteLine($"Page {result.PageNumber}: {result.Value}")
NextDocker部署
迁移到IronBarcode时,LEADTOOLS Docker 部署中定义的文件管理要求将完全消除。
LEADTOOLS 方法:
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY publish/ .
# License file must be physically present in the container image
COPY LEADTOOLS.LIC /app/license/LEADTOOLS.LIC
ENV LEADTOOLS_LICENSE_PATH=/app/license/LEADTOOLS.LIC
ENV LEADTOOLS_DEVELOPER_KEY=your-developer-key
ENTRYPOINT ["dotnet", "YourApp.dll"]
IronBarcode方法:
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY publish/ .
ENV IRONBARCODE_LICENSE=your-license-key
ENTRYPOINT ["dotnet", "YourApp.dll"]
许可证密钥在容器运行时通过 Docker secrets、Kubernetes secrets 或任何环境变量机制注入。 无需文件配置步骤。 Docker 和 Linux 部署指南涵盖 Alpine 和 Debian 基础镜像、多阶段构建和 Kubernetes 部署模式。
##LEADTOOLS条形码 API 到IronBarcode映射参考
| LEADTOOLS | IronBarcode | 备注 |
|---|---|---|
RasterSupport.SetLicense(path, key) | IronBarCode.License.LicenseKey = "key" | 仅密钥——无文件 |
RasterSupport.KernelExpired | (removed) | 无需检查有效期 |
RasterSupport.IsLocked(RasterSupportType.Barcode1DRead) | (removed) | 所有功能包括 |
RasterSupport.IsLocked(RasterSupportType.Barcode2DRead) | (removed) | 所有功能包括 |
RasterSupport.IsLocked(RasterSupportType.BarcodeWrite) | (removed) | 所有功能包括 |
new BarcodeEngine() | 静态 — 无实例 | BarcodeWriter 是静态的 |
new RasterCodecs() | (removed) | 直接传递文件路径 |
codecs.Load(imagePath) | (removed) | 直接传递文件路径 |
engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, symbologies) | BarcodeReader.Read(imagePath) | 自动检测符号体系 |
BarcodeData.Value | result.Value | 相同的属性名称 |
BarcodeData.Symbology | result.Format | 物业已更名 |
new BarcodeData() { Symbology = BarcodeSymbology.Code128 } | BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128) | 流畅的创作 |
BarcodeSymbology.Code128 | BarcodeEncoding.Code128 | 命名空间更改 |
BarcodeSymbology.QR | BarcodeEncoding.QRCode | 更名 |
BarcodeSymbology.DataMatrix | BarcodeEncoding.DataMatrix | 同名 |
BarcodeSymbology.PDF417 | BarcodeEncoding.PDF417 | 同名 |
BarcodeSymbology.EAN13 | BarcodeEncoding.EAN13 | 同名 |
BarcodeSymbology.UPCA | BarcodeEncoding.UPCA | 同名 |
BarcodeSymbology.Interleaved2of5 | BarcodeEncoding.Interleaved2of5 | 同名 |
BarcodeSymbology.Codabar | BarcodeEncoding.Codabar | 同名 |
engine.Writer.WriteBarcode(image, data, null) + codecs.Save(...) | .SaveAsPng(path) | 一种方法链 |
new RasterImage(...) + new FillCommand(RasterColor.White).Run(image) | (removed) | IronBarcode内部 |
常见迁移问题和解决方案
问题 1:CI/CD 中的 .LIC 文件引用
LEADTOOLS: CI/CD 管道在构建或部署LEADTOOLS应用时必须提供 .LIC 文件 —— 可以将其检查到源码控制中,将其从 base64 秘密中解码,或将其挂载为卷文物。 运行应用程序的每个流水线阶段都需要访问该文件。
解决方案: 从管道中删除所有 .LIC 文件处理。 替换为字符串秘密:
# Example: GitHub Actions environment variable
env:
IRONBARCODE_LICENSE: ${{secrets.IRONBARCODE_LICENSE}}
字符串值与其他字符串值凭据一起存储在 CI/CD 密钥存储中。 无需文件解码,无需工件配置,无需卷配置。
问题 2:MSVC++ 运行时对 Windows 的依赖性
LEADTOOLS: Windows Server 部署需要在主机上安装 MSVC++ 2017 运行时。用于LEADTOOLS部署的配置脚本、容器基础镜像和 Windows AMI 通常包含安装此运行时的步骤。
**解决方案:**从所有 Windows 配置脚本和容器映像中删除 MSVC++ 2017 运行时安装步骤。 IronBarcode没有原生运行时依赖项。 dotnet/aspnet 基础镜像无需额外的运行时包即可满足需求。
问题 3:栅格支持类型要素锁定检查
LEADTOOLS: 初始化顺序包括 RasterSupport.IsLocked() 每个条码功能的检查 —— Barcodes2D 和 BarcodeWrite。 这些检查是LEADTOOLS架构所需的防御性代码,用于验证许可证文件是否涵盖每个必需的功能。
解决方案: 删除所有 RasterSupport.IsLocked() 调用。 IronBarcode将所有读取和写入功能集成在一个许可证中。 没有针对每个功能的锁定状态,也不需要功能验证步骤:
// Remove these lines entirely:
// if (RasterSupport.IsLocked(RasterSupportType.Barcode1DRead)) ...
// if (RasterSupport.IsLocked(RasterSupportType.Barcode2DRead)) ...
// if (RasterSupport.IsLocked(RasterSupportType.BarcodeWrite)) ...' Remove these lines entirely:
' If RasterSupport.IsLocked(RasterSupportType.Barcode1DRead) ...
' If RasterSupport.IsLocked(RasterSupportType.Barcode2DRead) ...
' If RasterSupport.IsLocked(RasterSupportType.BarcodeWrite) ...问题 4:条形码符号数组移除
LEADTOOLS: 每个对 engine.Reader.ReadBarcodes() 的调用都需要一个显式的 BarcodeSymbology[] 参数。 如果条形码的符号体系未在数组中列出,则无法检测到该条形码,这可能会导致在输入文档中引入新的条形码类型时出现静默漏读。
**解决方法:**移除符号数组。 BarcodeReader.Read() 自动检测所有支持的格式。 如果已知格式集需要性能调整,BarcodeReaderOptions 提供可选提示而无需详尽枚举:
// Optional: hint the reader for performance in format-known scenarios
var options = new BarcodeReaderOptions
{
ExpectBarcodeTypes = BarcodeEncoding.Code128 | BarcodeEncoding.QRCode
};
var results = BarcodeReader.Read("scan.png", options);Imports System
' Optional: hint the reader for performance in format-known scenarios
Dim options As New BarcodeReaderOptions With {
.ExpectBarcodeTypes = BarcodeEncoding.Code128 Or BarcodeEncoding.QRCode
}
Dim results = BarcodeReader.Read("scan.png", options)##LEADTOOLS条形码迁移检查清单
迁移前任务
在进行任何更改之前,请审核代码库中所有LEADTOOLS的使用情况:
grep -r "using Leadtools" --include="*.cs" .
grep -r "RasterSupport\|BarcodeEngine\|RasterCodecs" --include="*.cs" .
grep -r "BarcodeSymbology\|BarcodeData\|RasterImage" --include="*.cs" .
grep -r "LEADTOOLS.LIC\|SetLicense\|KernelExpired" --include="*.cs" .
grep -r "COPY LEADTOOLS.LIC\|LEADTOOLS_LICENSE_PATH" --include="*.dockerfile" --include="Dockerfile" .
在开始代码更改之前,请记录初始化块、读取调用点、写入调用点和 Dockerfile 引用的数量和位置。
代码更新任务
- 删除所有五个LEADTOOLSNuGet包(如果存在,也请删除 PDF 编解码器)。
2.通过
dotnet add package IronBarcode安装IronBarcode3.用using IronBarCode替换所有using Leadtools.*命名空间导入 4.用IronBarCode.License.LicenseKey = "key"替换整个RasterSupport.SetLicense初始化块 5.删除所有RasterSupport.KernelExpired检查 6.删除所有RasterSupport.IsLocked(RasterSupportType.*)检查 7.删除所有new BarcodeEngine()实例化 8.从条码代码路径中删除所有new RasterCodecs()实例化 9.用BarcodeReader.Read(path)替换codecs.Load(path)+engine.Reader.ReadBarcodes(image, ...)10.用BarcodeWriter.CreateBarcode(...).SaveAsPng(path)替换new BarcodeData(...)+new RasterImage(...)+FillCommand+WriteBarcode+codecs.Save()11.用BarcodeEncoding.</em>替换BarcodeSymbology.<em>枚举引用(注意:QR成为QRCode) 12.从所有 Dockerfiles 中删除COPY LEADTOOLS.LIC行 13.从 Dockerfiles 和部署配置中删除LEADTOOLS_LICENSE_PATH和LEADTOOLS_DEVELOPER_KEY环境变量声明 14.将IRONBARCODE_LICENSE环境变量添加到 Dockerfiles 和秘密配置中 - 从 Windows 配置脚本中移除 MSVC++ 2017 运行时安装
迁移后测试
- 验证所有条码读取操作在以前由
BarcodeSymbology[]数组涵盖的所有符号类型中返回预期值 - 验证 Code 128、QR 码以及任何其他生成的条形码类型是否能生成有效、可扫描的输出
- 确认 PDF 条码提取没有
Leadtools.Pdf可正常工作 - 在不挂载任何
.LIC文件的情况下构建并启动容器镜像,并确认应用程序正确初始化 - 在没有
.LIC文件配置步骤的情况下运行 CI/CD 管道,并确认所有阶段成功完成 - 验证已发布的输出大小和容器镜像拉取时间是否有所改善
迁移到IronBarcode的主要优势
**简化的部署架构:**迁移后,每个环境(开发、CI、预发布、生产)都通过与 API 密钥、数据库密码和其他凭证相同的字符串值密钥机制接收许可证。 无需文件配置、无需工件处理、无需卷挂载。 添加新的部署环境与添加任何其他密钥的操作相同。
**减少依赖关系:**一个NuGet包取代了五个,并且消除了对 MSVC++ 2017 运行时的要求。 条形码服务的发布输出量从大约 148 MB 下降到大约 39 MB。 更小的镜像意味着更快的容器拉取速度、更低的容器注册表存储成本,以及在无服务器和自动扩展环境中更短的冷启动时间。
**简化的应用程序启动:**原本需要 20 行代码的LEADTOOLS初始化序列(包括文件路径解析、过期验证以及针对每个功能进行的三项锁定检查)被简化为一行代码。应用程序启动速度更快,并且初始化代码路径不依赖于任何文件系统,因此在新的环境中不会出现问题。
全面的格式检测: IronBarcode可读取所有 50 多种受支持的条码格式,而无需调用者指定预期格式。 未将某个符号学从LEADTOOLSBarcodeSymbology[] 数组中省略导致的静默未读风险已被消除。 当输入文档中出现新的条形码类型时, IronBarcode无需更改代码即可检测到它。
**可预测的总成本:**一次永久许可证购买即可涵盖开发、测试和无限次生产部署,无需部署跟踪,无需年度续订,也无需单独获取生产许可证。 团队可以在开始开发之前确认库的全部成本,而无需进行销售洽谈。
现代 API 设计: BarcodeReader.Read() 和 BarcodeWriter.CreateBarcode() 是接受文件路径的静态入口。LEADTOOLS读取和写入所需的多层对象构造(编解码器实例、引擎实例、图像分配、背景填充)由内部处理。 读取和生成条形码的代码更短,更容易审查和测试。

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。