.NETでバーコード リーダー SDK を構築する方法
IronBarcodeを使用すると、 .NET開発者は最小限のコードでアプリケーションにバーコード読み取り機能を追加できます。 1次元および2次元バーコード、様々な画像ソースを含む複数のフォーマットに対応し、機械学習に基づく検出により、生産環境において高い精度を実現します。
バーコードスキャンは、在庫管理から小売業、物流業まで、多くの用途において不可欠です。 .NETアプリケーションにバーコード読み取り機能を統合することで、データ収集の簡素化、ワークフローの自動化、効率性の向上を実現できます。 バーコードリーダーソリューションを評価する際には、対応フォーマット、処理速度、統合の複雑さなどの要素を考慮する必要があります。 IronBarcodeライブラリは、優れた耐障害性機能を備え、完全なクロスプラットフォーム互換性を提供します。
IronBarcodeは、バーコードの取り扱いを簡素化する効果的な.NETライブラリです。 このツールを使用すると、画像、ストリーム、 PDF ファイルからバーコードを読み取ることができ、 C# QR コードジェネレータを使用して QR コードを生成することもできます。 この記事では、バーコードスキャン機能を.NETアプリケーションに統合する方法を解説します。特に、バーコードスキャン機能を公開するためのAPIまたはWebアプリケーション統合の作成に焦点を当てます。 このライブラリは、1Dバーコードや2Dバーコードを含む様々なバーコード形式をサポートしており、高度な生成機能とスタイル設定オプションを備えています。
IronBarcode統合の最適なユースケースは何ですか?
IronBarcodeは、以下のシナリオで特に優れた性能を発揮します。
*在庫管理システム*–複数のバーコード読み取りと複数ページTIFF/GIFのサポートにより、製品追跡を自動化します。 物流アプリケーション–高速読み取りとカスタマイズ可能な出力フォーマットを使用して、出荷バーコードを処理します。 小売店向けPOSシステム– Code 39と1Dバーコード作成による取引の検証 文書処理–カスタムリーダー設定を使用してPDF請求書からデータを抽出 医療アプリケーション– 2Dフォーマットを使用してエラー訂正機能付きで患者IDを読み取る 製造品質管理**– 設定可能なバーコードマージンを使用してバッチ処理を実行します
.NETでバーコードリーダーSDKを作成するにはどうすればよいですか?
アプリケーション内でサービスとして公開できるバーコードリーダーを作成するには、 IronBarcodeをREST APIまたはWebアプリケーションに統合します。アーキテクチャの選択は、処理ニーズによって異なります。時折スキャンする場合は単一画像処理、ドキュメントワークフローの場合はバッチ処理、継続的なスキャンアプリケーションの場合はストリーム処理が適しています。 以下は、適切なスレッドセーフティを考慮したASP.NET Coreを使用した例です。 図書館の閲覧機能には、最適な精度を実現するための高度な画像作成フィルターが含まれています。
- NuGetパッケージを使用して、C# でバーコードを読み取るための.NETライブラリをインストールします。 2.適切なエラー処理を備えた再利用可能なバーコードスキャンクラスを作成する
- さまざまなソースからのバーコードを読み取る方法を開発する 4.設定の改善を使用して、バーコード画像読み取り機能をアプリケーションに統合します。 5.読書速度オプションを使用してパフォーマンスをテストおよび改善する
始める前に必要なものは何ですか?
まだダウンロードしていない場合は、プロジェクト用にIronBarcodeをダウンロードしてください。 ご使用目的に合った適切なライセンスキーをお持ちであることを確認してください。 IronBarcodeの機能をパブリックAPI経由で公開したり、スタンドアロンサービスとして再販したりするには、追加のライセンス(SDK、OEM、またはSaaS)が必要となることに注意してください。 手続きを進める前に、ライセンスオプションを必ず理解してください。 開発環境では、まず無料トライアルから始めて、本番環境への移行準備が整ったらライセンスキーを適用することができます。 最新の更新情報とマイルストーンについては、変更履歴を確認してください。
最適なパフォーマンスを得るには、デプロイ環境を考慮してください。 IronBarcodeは、 Windows 、 Linux 、 macOS 、 Docker 、 Azureや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
この改良されたクラスには、オプションのキャッシュ、スケーラビリティを向上させるための非同期処理、および精度を向上させるための画像フィルタによるパフォーマンスの最適化が含まれています。 この実装は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
Swagger UIではAPIはどのように表示されますか?

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)を取得する必要があります。 Enterprise向け導入の場合は、追加のユーザー数やサポートの強化のために利用可能なライセンス延長を検討してください。 デプロイメントの規模拡大に関するアップグレードオプションを確認してください。
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を使用したバーコードスキャンメソッドにおいて、堅牢なエラー処理を実装することで、バーコード読み取りの際のエラーを処理できます。例外をキャッチし、有意義なフィードバックを提供したり、再試行機構を組み込むことで、バーコード読み取りプロセスの信頼性を向上させます。
.NETバーコードライブラリをパブリックAPIで使用する際のライセンス要件は何ですか?
IronBarcodeをパブリックAPIで使用する際は、適切なライセンスを確保する必要があります。これは、ライブラリの機能を単独サービスやパブリックAPIとして公開する場合に追加の許可が必要となる、SDK、OEM、SaaSライセンスの取得を含みます。
複数のバーコードスキャンを.NETライブラリでバッチ処理できますか?
はい、IronBarcodeを使用して複数のバーコードスキャンをバッチ処理することが可能です。このライブラリは、一度の操作で複数のバーコードを読み取ることができ、大量の画像やドキュメントを効率的に処理するのに特に便利です。
.NETバーコードライブラリの試用版はありますか?
はい、IronBarcodeでは、バーコード生成、読み取り、編集機能を.NETアプリケーション内で探索できる無料の試用版を提供しています。この試用版は、ライブラリを購入する前に評価する手助けをします。



