如何在.NET中構建條碼讀取器SDK?
IronBarcode允許.NET開發人員用最少的程式碼將條碼讀取能力加入其應用程式。 它支援多種格式,包括一維和二維條碼、多種影像來源,並以機器學習為基礎的檢測提供高精度適用於生產環境。
條碼掃描對許多應用程式來說至關重要,從庫存管理到零售和物流。 通過將條碼讀取整合到您的.NET應用程式中,您可以簡化資料捕獲、自動化工作流程並提高效率。 在評估條碼讀取解決方案時,請考慮支援的格式、處理速度和整合複雜度等因素。 IronBarcode程式庫提供完全跨平台相容性及卓越的容錯特性。
IronBarcode是一個有效的.NET程式庫,簡化了與條碼的工作。 使用此工具,您可以從影像中讀取條碼,串流中,以及PDF檔案中讀取條碼,並使用C# QR程式碼生成器來生成QR程式碼。 本文向您展示如何將條碼掃描整合到您的.NET應用程式中,重點是建立一個API或Web應用整合以公開條碼掃描功能。 該程式庫支援各種條碼格式,包括一維和二維條碼,具有先進的生成能力和風格選項。
IronBarcode整合的最佳使用情境是什麼?
IronBarcode在這些場景中表現優異:
如何在.NET中建立條碼讀取器SDK?
要建立可以作為服務在您的應用程式中公開的條碼讀取器,請將IronBarcode整合到REST API或Web應用中。架構選擇取決於您的處理需求:偶爾掃描的單影像處理、檔案工作流程的批次處理或連續掃描應用的串流處理。 下面是使用ASP.NET Core的範例,包括適當的執行緒安全考量。 該程式庫的讀取功能包括先進的影像建立過濾器以達到最佳精度。
- 使用NuGet套件安裝用於C#讀取條碼的.NET程式庫
- 建立具有適當錯誤處理的可重用條碼掃描類
- 開發從不同來源讀取條碼的方法
- 使用進一步設置將條碼影像讀取整合到您的應用程式中
- 測試並使用讀取速度選項提升性能
開始之前我需要什麼?
若您尚未安裝,請下載IronBarcode用於您的專案。 確保您對應用場景擁有正確的授權金鑰。 請注意,通過公共API公開IronBarcode的功能或作為獨立服務轉售需額外的授權(SDK、OEM或SaaS)。 在繼續之前,確保您了解所有授權選項。 對於開發環境,您可以從免費試用開始,當準備好投入生產時應用您的授權金鑰。 查看版本日志獲取最新更新和里程碑。
為獲得最佳性能,請考慮您的部署環境。 IronBarcode supports cross-platform compatibility including Windows, Linux, macOS, Docker, and cloud platforms like Azure and AWS Lambda. 移動開發者可以通過Blazor整合使用對Android和iOS的支援。 對於.NET MAUI應用,請遵循條碼掃描器讀取器教程。
我如何建立一個條碼掃描器類?
在設置好IronBarcode並安裝到您的專案中之後,您可以建立一個可重用的條碼掃描器類,其整合了IronBarcode的功能並作為API端點公開。 實現包括性能優化和應對具有方位校正的挑戰性場景的影像校正。 考慮實施裁剪區域以在條碼位置可預測時加速處理:
using IronBarCode;
using System.IO;
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace BarcodeIntegration
{
public class BarcodeScanner
{
private static readonly ConcurrentDictionary<string, BarcodeReaderOptions> _optionsCache = new();
static BarcodeScanner()
{
// Set the license key
IronBarCode.License.LicenseKey = "Your-License-Key";
}
// Method to read a barcode from an image file with performance optimization
public string ReadBarcodeFromImage(string imagePath, BarcodeReadingSpeed speed = BarcodeReadingSpeed.Balanced)
{
try
{
var options = GetCachedOptions(speed);
// Try to read the barcode from the given image path
var barcode = BarcodeReader.Read(imagePath, options);
return barcode?.ToString() ?? "No Barcode Found"; // Return the barcode string or indicate no barcode was found
}
catch (Exception ex)
{
// Return an error message if an exception occurs
return $"Error reading barcode: {ex.Message}";
}
}
// Method to read a barcode from a stream (e.g., file upload or memory stream)
public async Task<string> ReadBarcodeFromStreamAsync(Stream inputStream)
{
try
{
var options = GetCachedOptions(BarcodeReadingSpeed.Detailed);
// Enable image correction for better accuracy
options.ImageFilters = new[] {
new SharpenFilter(),
new ContrastFilter()
};
// Try to read the barcode from the given stream
var barcode = await Task.Run(() => BarcodeReader.Read(inputStream, options));
return barcode?.ToString() ?? "No barcode found";
}
catch (Exception ex)
{
return $"Error reading barcode: {ex.Message}";
}
}
// Method to read a barcode from a PDF file with batch processing support
public async Task<List<string>> ReadBarcodesFromPdfAsync(string filePath)
{
try
{
var options = new BarcodeReaderOptions
{
ExpectMultipleBarcodes = true,
Speed = BarcodeReadingSpeed.Detailed
};
// Try to read barcodes from the given PDF file path
var barcodes = await Task.Run(() => BarcodeReader.ReadPdf(filePath, options));
return barcodes.Select(b => b.ToString()).ToList();
}
catch (Exception ex)
{
return new List<string> { $"Error reading barcode: {ex.Message}" };
}
}
// Cache reader options for performance
private BarcodeReaderOptions GetCachedOptions(BarcodeReadingSpeed speed)
{
return _optionsCache.GetOrAdd(speed.ToString(), _ => new BarcodeReaderOptions
{
Speed = speed,
AutoRotate = true,
RemoveFalsePositive = true
});
}
}
}
using IronBarCode;
using System.IO;
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace BarcodeIntegration
{
public class BarcodeScanner
{
private static readonly ConcurrentDictionary<string, BarcodeReaderOptions> _optionsCache = new();
static BarcodeScanner()
{
// Set the license key
IronBarCode.License.LicenseKey = "Your-License-Key";
}
// Method to read a barcode from an image file with performance optimization
public string ReadBarcodeFromImage(string imagePath, BarcodeReadingSpeed speed = BarcodeReadingSpeed.Balanced)
{
try
{
var options = GetCachedOptions(speed);
// Try to read the barcode from the given image path
var barcode = BarcodeReader.Read(imagePath, options);
return barcode?.ToString() ?? "No Barcode Found"; // Return the barcode string or indicate no barcode was found
}
catch (Exception ex)
{
// Return an error message if an exception occurs
return $"Error reading barcode: {ex.Message}";
}
}
// Method to read a barcode from a stream (e.g., file upload or memory stream)
public async Task<string> ReadBarcodeFromStreamAsync(Stream inputStream)
{
try
{
var options = GetCachedOptions(BarcodeReadingSpeed.Detailed);
// Enable image correction for better accuracy
options.ImageFilters = new[] {
new SharpenFilter(),
new ContrastFilter()
};
// Try to read the barcode from the given stream
var barcode = await Task.Run(() => BarcodeReader.Read(inputStream, options));
return barcode?.ToString() ?? "No barcode found";
}
catch (Exception ex)
{
return $"Error reading barcode: {ex.Message}";
}
}
// Method to read a barcode from a PDF file with batch processing support
public async Task<List<string>> ReadBarcodesFromPdfAsync(string filePath)
{
try
{
var options = new BarcodeReaderOptions
{
ExpectMultipleBarcodes = true,
Speed = BarcodeReadingSpeed.Detailed
};
// Try to read barcodes from the given PDF file path
var barcodes = await Task.Run(() => BarcodeReader.ReadPdf(filePath, options));
return barcodes.Select(b => b.ToString()).ToList();
}
catch (Exception ex)
{
return new List<string> { $"Error reading barcode: {ex.Message}" };
}
}
// Cache reader options for performance
private BarcodeReaderOptions GetCachedOptions(BarcodeReadingSpeed speed)
{
return _optionsCache.GetOrAdd(speed.ToString(), _ => new BarcodeReaderOptions
{
Speed = speed,
AutoRotate = true,
RemoveFalsePositive = true
});
}
}
}
Imports IronBarCode
Imports System.IO
Imports System.Collections.Concurrent
Imports System.Threading.Tasks
Namespace BarcodeIntegration
Public Class BarcodeScanner
Private Shared ReadOnly _optionsCache As New ConcurrentDictionary(Of String, BarcodeReaderOptions)()
Shared Sub New()
' Set the license key
IronBarCode.License.LicenseKey = "Your-License-Key"
End Sub
' Method to read a barcode from an image file with performance optimization
Public Function ReadBarcodeFromImage(imagePath As String, Optional speed As BarcodeReadingSpeed = BarcodeReadingSpeed.Balanced) As String
Try
Dim options = GetCachedOptions(speed)
' Try to read the barcode from the given image path
Dim barcode = BarcodeReader.Read(imagePath, options)
Return If(barcode?.ToString(), "No Barcode Found") ' Return the barcode string or indicate no barcode was found
Catch ex As Exception
' Return an error message if an exception occurs
Return $"Error reading barcode: {ex.Message}"
End Try
End Function
' Method to read a barcode from a stream (e.g., file upload or memory stream)
Public Async Function ReadBarcodeFromStreamAsync(inputStream As Stream) As Task(Of String)
Try
Dim options = GetCachedOptions(BarcodeReadingSpeed.Detailed)
' Enable image correction for better accuracy
options.ImageFilters = {New SharpenFilter(), New ContrastFilter()}
' Try to read the barcode from the given stream
Dim barcode = Await Task.Run(Function() BarcodeReader.Read(inputStream, options))
Return If(barcode?.ToString(), "No barcode found")
Catch ex As Exception
Return $"Error reading barcode: {ex.Message}"
End Try
End Function
' Method to read a barcode from a PDF file with batch processing support
Public Async Function ReadBarcodesFromPdfAsync(filePath As String) As Task(Of List(Of String))
Try
Dim options = New BarcodeReaderOptions With {
.ExpectMultipleBarcodes = True,
.Speed = BarcodeReadingSpeed.Detailed
}
' Try to read barcodes from the given PDF file path
Dim barcodes = Await Task.Run(Function() BarcodeReader.ReadPdf(filePath, options))
Return barcodes.Select(Function(b) b.ToString()).ToList()
Catch ex As Exception
Return New List(Of String) From {$"Error reading barcode: {ex.Message}"}
End Try
End Function
' Cache reader options for performance
Private Function GetCachedOptions(speed As BarcodeReadingSpeed) As BarcodeReaderOptions
Return _optionsCache.GetOrAdd(speed.ToString(), Function(_) New BarcodeReaderOptions With {
.Speed = speed,
.AutoRotate = True,
.RemoveFalsePositive = True
})
End Function
End Class
End Namespace
改進的BarcodeScanner類透過選項快取提高性能,使用非同步處理提升可擴展性,並使用影像過濾器提高準確性。 實施遵循SOLID原則並提供適用於生產環境的錯誤處理。 若需額外功能,考慮使用System.Drawing整合或作為流導出。 您還可以建立條碼影像,使用自訂條碼風格和QR碼風格化。
我應使用哪些方法來讀取不同的條碼來源?
每個方法因特定使用者情境和處理需求而有所改善:
ReadBarcodeFromImage(string imagePath):從影像檔案中讀取條碼。ReadBarcodeFromStream(Stream inputStream):從輸入流(例如檔案上傳或記憶體流)中讀取條碼。ReadBarcodeFromPdf(string filePath):從PDF檔案中讀取條碼。
對於高流量情境,考慮使用裁剪區域提升處理速度最多5倍當條碼位置可預測時。 您還可以建立條碼影像或以多種格式保存條碼。 該程式庫支援從System.Drawing讀取物件,並可將條碼導出為HTML或PDF文件。
如何通過REST API公開條碼讀取功能?
為使外部應用程式可使用您的條碼掃描功能,請使用ASP.NET Core將其作為REST API公開。 實施中包括適當的錯誤處理、驗證和多種輸入格式的支援。 您還可以使用C#條碼影像生成器生成條碼或探索快速開始範例。 當處理PDF時,考慮在現有PDF上加蓋條碼來進行文件跟踪:
using Microsoft.AspNetCore.Mvc;
using System.IO;
using Microsoft.AspNetCore.Http;
using BarcodeIntegration;
[ApiController]
[Route("api/barcode")]
public class BarcodeController : ControllerBase
{
private readonly BarcodeScanner _barcodeScanner;
private readonly ILogger<BarcodeController> _logger;
public BarcodeController(ILogger<BarcodeController> logger)
{
_barcodeScanner = new BarcodeScanner();
_logger = logger;
}
// POST endpoint to read barcode from an uploaded image
[HttpPost("read-from-image")]
public async Task<IActionResult> ReadFromImage(IFormFile file)
{
if (file == null || file.Length == 0)
return BadRequest(new { Error = "No file uploaded" });
// Validate file type
var allowedTypes = new[] { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tiff" };
if (!allowedTypes.Contains(file.ContentType.ToLower()))
return BadRequest(new { Error = "Unsupported file type" });
try
{
using var stream = file.OpenReadStream();
var result = await _barcodeScanner.ReadBarcodeFromStreamAsync(stream);
_logger.LogInformation($"Barcode read successfully from {file.FileName}");
return Ok(new { Barcode = result, FileName = file.FileName });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing barcode");
return StatusCode(500, new { Error = "Internal server error" });
}
}
// POST endpoint for batch processing
[HttpPost("read-batch")]
public async Task<IActionResult> ReadBatch(List<IFormFile> files)
{
var results = new List<object>();
foreach (var file in files)
{
using var stream = file.OpenReadStream();
var result = await _barcodeScanner.ReadBarcodeFromStreamAsync(stream);
results.Add(new { FileName = file.FileName, Barcode = result });
}
return Ok(new { Results = results, Count = results.Count });
}
// POST endpoint to generate barcode from data
[HttpPost("generate")]
public IActionResult GenerateBarcode([FromBody] BarcodeGenerationRequest request)
{
try
{
// Create barcode with specified data and format
var barcode = BarcodeWriter.CreateBarcode(request.Data, request.Format ?? BarcodeWriterEncoding.Code128);
// Apply custom styling if requested
if (request.Width.HasValue && request.Height.HasValue)
barcode.ResizeTo(request.Width.Value, request.Height.Value);
if (!string.IsNullOrEmpty(request.ForegroundColor))
barcode.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml(request.ForegroundColor));
// Return as base64 encoded image
using var ms = barcode.ToStream();
var bytes = ms.ToArray();
return Ok(new {
Image = Convert.ToBase64String(bytes),
Format = request.Format?.ToString() ?? "Code128",
Data = request.Data
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error generating barcode");
return BadRequest(new { Error = "Failed to generate barcode" });
}
}
}
public class BarcodeGenerationRequest
{
public string Data { get; set; }
public BarcodeWriterEncoding? Format { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public string ForegroundColor { get; set; }
}
using Microsoft.AspNetCore.Mvc;
using System.IO;
using Microsoft.AspNetCore.Http;
using BarcodeIntegration;
[ApiController]
[Route("api/barcode")]
public class BarcodeController : ControllerBase
{
private readonly BarcodeScanner _barcodeScanner;
private readonly ILogger<BarcodeController> _logger;
public BarcodeController(ILogger<BarcodeController> logger)
{
_barcodeScanner = new BarcodeScanner();
_logger = logger;
}
// POST endpoint to read barcode from an uploaded image
[HttpPost("read-from-image")]
public async Task<IActionResult> ReadFromImage(IFormFile file)
{
if (file == null || file.Length == 0)
return BadRequest(new { Error = "No file uploaded" });
// Validate file type
var allowedTypes = new[] { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tiff" };
if (!allowedTypes.Contains(file.ContentType.ToLower()))
return BadRequest(new { Error = "Unsupported file type" });
try
{
using var stream = file.OpenReadStream();
var result = await _barcodeScanner.ReadBarcodeFromStreamAsync(stream);
_logger.LogInformation($"Barcode read successfully from {file.FileName}");
return Ok(new { Barcode = result, FileName = file.FileName });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing barcode");
return StatusCode(500, new { Error = "Internal server error" });
}
}
// POST endpoint for batch processing
[HttpPost("read-batch")]
public async Task<IActionResult> ReadBatch(List<IFormFile> files)
{
var results = new List<object>();
foreach (var file in files)
{
using var stream = file.OpenReadStream();
var result = await _barcodeScanner.ReadBarcodeFromStreamAsync(stream);
results.Add(new { FileName = file.FileName, Barcode = result });
}
return Ok(new { Results = results, Count = results.Count });
}
// POST endpoint to generate barcode from data
[HttpPost("generate")]
public IActionResult GenerateBarcode([FromBody] BarcodeGenerationRequest request)
{
try
{
// Create barcode with specified data and format
var barcode = BarcodeWriter.CreateBarcode(request.Data, request.Format ?? BarcodeWriterEncoding.Code128);
// Apply custom styling if requested
if (request.Width.HasValue && request.Height.HasValue)
barcode.ResizeTo(request.Width.Value, request.Height.Value);
if (!string.IsNullOrEmpty(request.ForegroundColor))
barcode.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml(request.ForegroundColor));
// Return as base64 encoded image
using var ms = barcode.ToStream();
var bytes = ms.ToArray();
return Ok(new {
Image = Convert.ToBase64String(bytes),
Format = request.Format?.ToString() ?? "Code128",
Data = request.Data
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error generating barcode");
return BadRequest(new { Error = "Failed to generate barcode" });
}
}
}
public class BarcodeGenerationRequest
{
public string Data { get; set; }
public BarcodeWriterEncoding? Format { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public string ForegroundColor { get; set; }
}
Imports Microsoft.AspNetCore.Mvc
Imports System.IO
Imports Microsoft.AspNetCore.Http
Imports BarcodeIntegration
<ApiController>
<Route("api/barcode")>
Public Class BarcodeController
Inherits ControllerBase
Private ReadOnly _barcodeScanner As BarcodeScanner
Private ReadOnly _logger As ILogger(Of BarcodeController)
Public Sub New(logger As ILogger(Of BarcodeController))
_barcodeScanner = New BarcodeScanner()
_logger = logger
End Sub
' POST endpoint to read barcode from an uploaded image
<HttpPost("read-from-image")>
Public Async Function ReadFromImage(file As IFormFile) As Task(Of IActionResult)
If file Is Nothing OrElse file.Length = 0 Then
Return BadRequest(New With {.Error = "No file uploaded"})
End If
' Validate file type
Dim allowedTypes = New String() {"image/jpeg", "image/png", "image/gif", "image/bmp", "image/tiff"}
If Not allowedTypes.Contains(file.ContentType.ToLower()) Then
Return BadRequest(New With {.Error = "Unsupported file type"})
End If
Try
Using stream = file.OpenReadStream()
Dim result = Await _barcodeScanner.ReadBarcodeFromStreamAsync(stream)
_logger.LogInformation($"Barcode read successfully from {file.FileName}")
Return Ok(New With {.Barcode = result, .FileName = file.FileName})
End Using
Catch ex As Exception
_logger.LogError(ex, "Error processing barcode")
Return StatusCode(500, New With {.Error = "Internal server error"})
End Try
End Function
' POST endpoint for batch processing
<HttpPost("read-batch")>
Public Async Function ReadBatch(files As List(Of IFormFile)) As Task(Of IActionResult)
Dim results = New List(Of Object)()
For Each file In files
Using stream = file.OpenReadStream()
Dim result = Await _barcodeScanner.ReadBarcodeFromStreamAsync(stream)
results.Add(New With {.FileName = file.FileName, .Barcode = result})
End Using
Next
Return Ok(New With {.Results = results, .Count = results.Count})
End Function
' POST endpoint to generate barcode from data
<HttpPost("generate")>
Public Function GenerateBarcode(<FromBody> request As BarcodeGenerationRequest) As IActionResult
Try
' Create barcode with specified data and format
Dim barcode = BarcodeWriter.CreateBarcode(request.Data, If(request.Format, BarcodeWriterEncoding.Code128))
' Apply custom styling if requested
If request.Width.HasValue AndAlso request.Height.HasValue Then
barcode.ResizeTo(request.Width.Value, request.Height.Value)
End If
If Not String.IsNullOrEmpty(request.ForegroundColor) Then
barcode.ChangeBarCodeColor(System.Drawing.ColorTranslator.FromHtml(request.ForegroundColor))
End If
' Return as base64 encoded image
Using ms = barcode.ToStream()
Dim bytes = ms.ToArray()
Return Ok(New With {
.Image = Convert.ToBase64String(bytes),
.Format = If(request.Format?.ToString(), "Code128"),
.Data = request.Data
})
End Using
Catch ex As Exception
_logger.LogError(ex, "Error generating barcode")
Return BadRequest(New With {.Error = "Failed to generate barcode"})
End Try
End Function
End Class
Public Class BarcodeGenerationRequest
Public Property Data As String
Public Property Format As BarcodeWriterEncoding?
Public Property Width As Integer?
Public Property Height As Integer?
Public Property ForegroundColor As String
End Class
API在Swagger UI中的樣子如何?

API響應的樣子如何?

此API公開POST端點,您可以上傳條碼影像,API返回條碼資料。 實施中包括適當的驗證、錯誤處理和日誌記錄以供生產使用。 對於行動應用程式,考慮增加適合較小影像尺寸和更快響應時間的端點。 您還可以從資料建立條碼或將其導出為HTML或PDF。 對於高對比度要求,生成1-BPP條碼影像。## 我可以新增哪些高級功能?
為進一步提高您的SDK,請考慮使用IronBarcode的完整API參考實施這些適合生產環境的功能。 探索功能概述和查看演示以獲取實際應用:
如何支援多種條碼型別?
IronBarcode支援同時讀取多個條碼。 您可以配置您的SDK同時接受多個條碼並使用特定格式過濾。 該程式庫支援寫入Unicode條碼,包括中文和阿拉伯字元。 對於專用應用程式,探索Code 39讀取和使用自訂風格建立QR碼:
public async Task<List<BarcodeResult>> ReadMultipleBarcodesAsync(string imagePath, BarcodeEncoding[] expectedTypes = null)
{
try
{
var options = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = true,
ExpectBarcodeTypes = expectedTypes ?? BarcodeEncoding.All,
Speed = BarcodeReadingSpeed.Detailed,
MaxParallelThreads = Environment.ProcessorCount,
Multithreaded = true
};
// Apply confidence threshold for machine learning accuracy
options.Confidence = Confidence.High;
var results = await Task.Run(() => BarcodeReader.Read(imagePath, options));
return results.Select(barcode => new BarcodeResult
{
Value = barcode.ToString(),
Format = barcode.BarcodeType.ToString(),
Confidence = barcode.Confidence,
Position = barcode.Rect
}).ToList();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error reading multiple barcodes");
throw;
}
}
public async Task<List<BarcodeResult>> ReadMultipleBarcodesAsync(string imagePath, BarcodeEncoding[] expectedTypes = null)
{
try
{
var options = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = true,
ExpectBarcodeTypes = expectedTypes ?? BarcodeEncoding.All,
Speed = BarcodeReadingSpeed.Detailed,
MaxParallelThreads = Environment.ProcessorCount,
Multithreaded = true
};
// Apply confidence threshold for machine learning accuracy
options.Confidence = Confidence.High;
var results = await Task.Run(() => BarcodeReader.Read(imagePath, options));
return results.Select(barcode => new BarcodeResult
{
Value = barcode.ToString(),
Format = barcode.BarcodeType.ToString(),
Confidence = barcode.Confidence,
Position = barcode.Rect
}).ToList();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error reading multiple barcodes");
throw;
}
}
Imports System
Imports System.Collections.Generic
Imports System.Threading.Tasks
Public Async Function ReadMultipleBarcodesAsync(imagePath As String, Optional expectedTypes As BarcodeEncoding() = Nothing) As Task(Of List(Of BarcodeResult))
Try
Dim options As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = If(expectedTypes, BarcodeEncoding.All),
.Speed = BarcodeReadingSpeed.Detailed,
.MaxParallelThreads = Environment.ProcessorCount,
.Multithreaded = True
}
' Apply confidence threshold for machine learning accuracy
options.Confidence = Confidence.High
Dim results = Await Task.Run(Function() BarcodeReader.Read(imagePath, options))
Return results.Select(Function(barcode) New BarcodeResult With {
.Value = barcode.ToString(),
.Format = barcode.BarcodeType.ToString(),
.Confidence = barcode.Confidence,
.Position = barcode.Rect
}).ToList()
Catch ex As Exception
_logger.LogError(ex, "Error reading multiple barcodes")
Throw
End Try
End Function
我應考慮其他哪些改進?
- 錯誤處理:實施完整的錯誤處理,包括MSI條碼識別
- 批次處理:建立異步批次處理方法使用1-BPP條碼影像
- 性能監控:使用讀取速度配置新增度量
- 快取:實施頻繁掃描條碼的結果快取
- 影像預處理:使用方位校正和對比過濾器
- 格式特定優化:為GS1-128和新格式配置設置
WebSocket支援:新增實時條碼掃描進行持續監控- 自訂風格:應用條碼風格和QR碼自訂化
對於生產部署,考慮實施信心水準以減少假陽性並確保資料准確性。 機器學習為基礎的檢測可以根據您的特定使用情境進行調整。 在建立部署包時,請遵循MSI安裝程式指南並解決任何缺少DLL問題。 對於AWS部署,請注意潛在的運行時問題。 考慮建立條碼並選擇各種輸出資料格式,並探索條碼讀取教程。
我需要了解哪些授權考慮事項?
如前所述,IronBarcode SDK旨在整合到您的內部應用程式中,並通過API公開需要額外的授權。 您必須在將IronBarcode作為服務的一部分,例如公共API時確保必要的授權(SDK、OEM或SaaS)。 對於企業部署,考慮可用於增加座位或提高支援的授權擴展。 查看升級選項以擴展您的部署。
不要將IronBarcode作為獨立的SDK轉售,亦不可通過公共面向API公開而不確保您的授權涵蓋此使用。 對於網頁應用,您可能需要配置web.config中的授權金鑰以便正確激活。 保持對安全CVE更新的關注,並遵循運行時複製異常的最佳實踐。 對於技術問題,考慮提交工程請求。 查看關於撰寫Unicode條碼的資源並探索條碼讀取教程。
為何我應該立即嘗試IronBarcode?
體驗IronBarcode的新功能。 試用我們的免費試用版,並發現流暢的條碼生成、讀取和編輯功能,用於您的.NET應用程式。 擁有先進的功能、卓越的性能和使用者友好的介面,IronBarcode是解決您所有條碼需求的最佳方案。 探索我們的完整文件,複查程式碼範例,並查看實況演示以了解全部功能。 查看條碼讀取的教程並探索MicroQR和rMQR支援。 了解NuGet包選項以適用不同的部署場景。 您還可以瀏覽IronBarcode文件以獲取更多有關我們完整條碼解決方案的資訊。 今天開始免費試用並改善您的專案。
常見問題
如何將條碼讀取器整合到.NET應用中?
您可以使用IronBarcode程式庫將條碼讀取器整合到.NET應用中。首先,安裝IronBarcode,然後建立一個用於條碼掃描的類,並實現從圖像、流和PDF中讀取條碼的方法。最後,測試並優化您的設置。
我如何將條碼讀取功能公開為REST API?
要將條碼讀取功能公開為REST API,可以使用ASP.NET Core建立網頁應用。結合IronBarcode程式庫,開發BarcodeScanner類,並定義使用ReadBarcodeFromImage和ReadBarcodeFromStream等方法讀取條碼的API端點。
使用.NET條碼程式庫可以讀取哪些條碼型別?
類似IronBarcode的.NET條碼程式庫可以讀取各種條碼型別,包括QR碼、Code 128、UPC和EAN。您可以通過設置檢測參數來配置程式庫同時檢測多種型別的條碼。
如何在.NET中處理讀取條碼時的錯誤?
在條碼讀取中處理錯誤可以通過在條碼掃描方法中使用IronBarcode實現穩健的錯誤處理來實現。確保捕獲異常並提供有意義的反饋或重試機制,以提高條碼讀取過程的可靠性。
在公共API中使用.NET條碼函式庫的授權要求是什麼?
在公共API中使用IronBarcode時,您必須確保適當的授權。這包括獲得SDK、OEM或SaaS授權,因為將函式庫的功能公開為獨立服務或公共API需要額外的許可。
我可以使用.NET函式庫批量處理多個條碼掃描嗎?
是的,您可以使用IronBarcode批量處理多個條碼掃描。函式庫允許您在單次操作中讀取多個條碼,這對於有效處理大批量圖像或文件特別有用。
是否有.NET條碼函式庫的試用版本?
是的,IronBarcode提供免費試用版,允許您在.NET應用中探索其條碼生成、讀取和編輯功能。這一試用可以幫助您在購買前評估函式庫。




