C#バーコードスキャナー: .NETアプリケーションでバーコードとQRコードを読み取る
.NETアプリケーションでバーコードやQRコードを素早くスキャンする必要がありますか? IronBarcodeは、完璧なデジタル画像でも、読み取りが難しい実際の写真でも、バーコードの読み取りを簡単で信頼できるものにします。 このガイドでは、C#でのバーコードスキャンの実装方法を実際にすぐ使える実例と共に示しています。
クイックスタート: ファイルからバーコードを瞬時に読み取るこの短い例は、IronBarcodeを使い始めるのがどれだけ簡単かを示しています。 1行のコードで画像ファイルからバーコードを読み取ることができます - 複雑なセットアップは不要です。
-
1IronBarcode を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
var results = IronBarCode.BarcodeReader.Read("path/to/barcode.png");Dim results = IronBarCode.BarcodeReader.Read("path/to/barcode.png")Dim results = IronBarCode.BarcodeReader.Read("path/to/barcode.png") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronBarcodeを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- NuGetからまたはDLLのダウンロード経由でIronBarcodeをインストールする
BarcodeReader.Readメソッドを使用して、任意のバーコードまたは QR コードをスキャンします。- 1 回のスキャン、PDF、またはマルチフレーム TIFF ファイルで複数のバーコードまたは QR コードを読み取ります
- IronBarcode を有効にして、高度なフィルターを使用して不完全なスキャンや写真をデコードします
- チュートリアルプロジェクトをダウンロードしてすぐにスキャンを開始してください
どうやって.NETプロジェクトにIronBarcodeをインストールしますか?
IronBarcodeは、NuGetパッケージマネージャーまたはDLLを直接ダウンロードすることで簡単にインストールできます。 NuGetによるインストールは依存関係と更新を自動で管理するため推奨される方法です。
インストール後、using IronBarCode;をC#ファイルに追加して、バーコードスキャン機能にアクセスします。 異なる開発環境での詳細なインストール手順は、インストールガイドをご確認ください。
C#で最初のバーコードをどのようにして読むことができますか?
IronBarcodeでバーコードを読むのに必要なのは、コード1行だけです。 ライブラリは自動的にバーコードフォーマットを検出し、すべてのエンコードされたデータを抽出します。
IronBarcodeが瞬時に読み取れる標準のCode128バーコードusing IronBarCode;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Choose which filters are to be applied (in order)
ImageFilters = new ImageFilterCollection() {
new AdaptiveThresholdFilter(),
},
// Uses machine learning to auto rotate the barcode
AutoRotate = true,
};
// Read barcode
BarcodeResults results = BarcodeReader.Read("TryHarderQR.png", options);using IronBarCode;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Choose which filters are to be applied (in order)
ImageFilters = new ImageFilterCollection() {
new AdaptiveThresholdFilter(),
},
// Uses machine learning to auto rotate the barcode
AutoRotate = true,
};
// Read barcode
BarcodeResults results = BarcodeReader.Read("TryHarderQR.png", options);Imports IronBarCode
Private options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection() From {New AdaptiveThresholdFilter()},
.AutoRotate = True
}
' Read barcode
Private results As BarcodeResults = BarcodeReader.Read("TryHarderQR.png", options)Imports IronBarCode
Private options As New BarcodeReaderOptions() With {
.ImageFilters = New ImageFilterCollection() From {New AdaptiveThresholdFilter()},
.AutoRotate = True
}
' Read barcode
Private results As BarcodeResults = BarcodeReader.Read("TryHarderQR.png", options)BarcodeReader.Read メソッドは、検出されたすべてのバーコードを含む BarcodeResults コレクションを返します。 各BarcodeResultは、バーコードのテキスト値、フォーマットタイプ、位置座標、バイナリデータへのアクセスを提供します。 このアプローチは、Code128、Code39、QRコード、データマトリックスコードを含む一般的なバーコードフォーマットで機能します。
読み取りが難しいバーコードや損傷したバーコードに役立つオプションは何ですか?
実際のバーコードスキャンでは、斜めに撮影された画像、照明条件の悪い画像、一部が損傷した画像など、不完全な画像を扱うことがよくあります。IronBarcodeの高度なオプションを使用すると、これらの問題に効果的に対処できます。
using IronBarCode;
using System;
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
BarcodeResults results = BarcodeReader.ReadPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var pageResult in results)
{
string Value = pageResult.Value;
int PageNum = pageResult.PageNumber;
System.Drawing.Bitmap Img = pageResult.BarcodeImage;
BarcodeEncoding BarcodeType = pageResult.BarcodeType;
byte[] Binary = pageResult.BinaryValue;
Console.WriteLine(pageResult.Value + " on page " + PageNum);
}using IronBarCode;
using System;
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
BarcodeResults results = BarcodeReader.ReadPdf("MultipleBarcodes.pdf");
// Work with the results
foreach (var pageResult in results)
{
string Value = pageResult.Value;
int PageNum = pageResult.PageNumber;
System.Drawing.Bitmap Img = pageResult.BarcodeImage;
BarcodeEncoding BarcodeType = pageResult.BarcodeType;
byte[] Binary = pageResult.BinaryValue;
Console.WriteLine(pageResult.Value + " on page " + PageNum);
}Imports IronBarCode
Imports System
' Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
Private results As BarcodeResults = BarcodeReader.ReadPdf("MultipleBarcodes.pdf")
' Work with the results
For Each pageResult In results
Dim Value As String = pageResult.Value
Dim PageNum As Integer = pageResult.PageNumber
Dim Img As System.Drawing.Bitmap = pageResult.BarcodeImage
Dim BarcodeType As BarcodeEncoding = pageResult.BarcodeType
Dim Binary() As Byte = pageResult.BinaryValue
Console.WriteLine(pageResult.Value & " on page " & PageNum)
Next pageResultImports IronBarCode
Imports System
' Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
Private results As BarcodeResults = BarcodeReader.ReadPdf("MultipleBarcodes.pdf")
' Work with the results
For Each pageResult In results
Dim Value As String = pageResult.Value
Dim PageNum As Integer = pageResult.PageNumber
Dim Img As System.Drawing.Bitmap = pageResult.BarcodeImage
Dim BarcodeType As BarcodeEncoding = pageResult.BarcodeType
Dim Binary() As Byte = pageResult.BinaryValue
Console.WriteLine(pageResult.Value & " on page " & PageNum)
Next pageResult
IronBarcode が高度なオプションを使用して正常に読み取った回転した QR コードこのプロパティExpectBarcodeTypesは特定のフォーマットに検索を限定することでパフォーマンスを大幅に向上させます。 問題のある画像で最大の精度を得るためには、画像フィルターを自動回転と組み合わせて使用します:
using IronBarCode;
// Multi frame TIFF and GIF images can also be scanned
BarcodeResults multiFrameResults = BarcodeReader.Read("Multiframe.tiff");
foreach (var pageResult in multiFrameResults)
{
//...
}using IronBarCode;
// Multi frame TIFF and GIF images can also be scanned
BarcodeResults multiFrameResults = BarcodeReader.Read("Multiframe.tiff");
foreach (var pageResult in multiFrameResults)
{
//...
}Imports IronBarCode
' Multi frame TIFF and GIF images can also be scanned
Private multiFrameResults As BarcodeResults = BarcodeReader.Read("Multiframe.tiff")
For Each pageResult In multiFrameResults
'...
Next pageResultImports IronBarCode
' Multi frame TIFF and GIF images can also be scanned
Private multiFrameResults As BarcodeResults = BarcodeReader.Read("Multiframe.tiff")
For Each pageResult In multiFrameResults
'...
Next pageResultこれらの高度な機能により、IronBarcodeは写真からのバーコードスキャンに加え、画質のばらつきが大きいセキュリティカメラやモバイルデバイスの撮影画像からの読み取りにも適しています。
PDFドキュメントから複数のバーコードをスキャンする方法は?
PDFバーコードスキャンは、請求書、出荷ラベル、在庫ドキュメントの処理に不可欠です。 IronBarcodeは、すべてのページのバーコードを効率的に読み取ります。
PDFファイルからのバーコード読み取り
using IronBarCode;
// The Multithreaded property allows for faster barcode scanning across multiple images or PDFs. All threads are automatically managed by IronBarCode.
var ListOfDocuments = new[] { "image1.png", "image2.JPG", "image3.pdf" };
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Enable multithreading
Multithreaded = true,
};
BarcodeResults batchResults = BarcodeReader.Read(ListOfDocuments, options);using IronBarCode;
// The Multithreaded property allows for faster barcode scanning across multiple images or PDFs. All threads are automatically managed by IronBarCode.
var ListOfDocuments = new[] { "image1.png", "image2.JPG", "image3.pdf" };
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Enable multithreading
Multithreaded = true,
};
BarcodeResults batchResults = BarcodeReader.Read(ListOfDocuments, options);Imports IronBarCode
' The Multithreaded property allows for faster barcode scanning across multiple images or PDFs. All threads are automatically managed by IronBarCode.
Private ListOfDocuments = { "image1.png", "image2.JPG", "image3.pdf" }
Private options As New BarcodeReaderOptions() With {.Multithreaded = True}
Private batchResults As BarcodeResults = BarcodeReader.Read(ListOfDocuments, options)Imports IronBarCode
' The Multithreaded property allows for faster barcode scanning across multiple images or PDFs. All threads are automatically managed by IronBarCode.
Private ListOfDocuments = { "image1.png", "image2.JPG", "image3.pdf" }
Private options As New BarcodeReaderOptions() With {.Multithreaded = True}
Private batchResults As BarcodeResults = BarcodeReader.Read(ListOfDocuments, options)
異なるPDFページで見つかった複数バーコードを示すコンソール出力
特定のページ範囲や高度なPDF処理には、BarcodeReaderOptionsを使用してください。
// Read only specific pages to improve performance
PdfBarcodeReaderOptions pdfOptions = new PdfBarcodeReaderOptions
{
// Scan pages 1-5 only
PageNumbers = new[] { 1, 2, 3, 4, 5 },
// PDF-specific settings
DPI = 300 // Higher DPI for better accuracy
};
BarcodeResults results = BarcodeReader.ReadPdf("document.pdf", pdfOptions);// Read only specific pages to improve performance
PdfBarcodeReaderOptions pdfOptions = new PdfBarcodeReaderOptions
{
// Scan pages 1-5 only
PageNumbers = new[] { 1, 2, 3, 4, 5 },
// PDF-specific settings
DPI = 300 // Higher DPI for better accuracy
};
BarcodeResults results = BarcodeReader.ReadPdf("document.pdf", pdfOptions);' Read only specific pages to improve performance
Dim pdfOptions As New PdfBarcodeReaderOptions() With {
' Scan pages 1-5 only
.PageNumbers = New Integer() { 1, 2, 3, 4, 5 },
' PDF-specific settings
.DPI = 300 ' Higher DPI for better accuracy
}
Dim results As BarcodeResults = BarcodeReader.ReadPdf("document.pdf", pdfOptions)' Read only specific pages to improve performance
Dim pdfOptions As New PdfBarcodeReaderOptions() With {
' Scan pages 1-5 only
.PageNumbers = New Integer() { 1, 2, 3, 4, 5 },
' PDF-specific settings
.DPI = 300 ' Higher DPI for better accuracy
}
Dim results As BarcodeResults = BarcodeReader.ReadPdf("document.pdf", pdfOptions)マルチフレームTIFF画像を処理する方法は?
ドキュメント スキャニングやファクシミリ システムで一般的なマルチフレームTIFFファイルは、PDFと同様の包括的なサポートを受けます。
異なるフレームにバーコードを持つマルチフレームTIFFファイル
using IronBarCode;
using System;
// TIFF files are processed similarly to regular images
// Each frame is scanned automatically
BarcodeResults multiFrameResults = BarcodeReader.Read("Multiframe.tiff");
foreach (var result in multiFrameResults)
{
// Access frame-specific information
int frameNumber = result.PageNumber; // Frame number in TIFF
string barcodeValue = result.Text;
Console.WriteLine($"Frame {frameNumber}: {barcodeValue}");
// Save individual barcode images if needed
result.BarcodeImage?.SaveAs($"barcode_frame_{frameNumber}.png");
}using IronBarCode;
using System;
// TIFF files are processed similarly to regular images
// Each frame is scanned automatically
BarcodeResults multiFrameResults = BarcodeReader.Read("Multiframe.tiff");
foreach (var result in multiFrameResults)
{
// Access frame-specific information
int frameNumber = result.PageNumber; // Frame number in TIFF
string barcodeValue = result.Text;
Console.WriteLine($"Frame {frameNumber}: {barcodeValue}");
// Save individual barcode images if needed
result.BarcodeImage?.SaveAs($"barcode_frame_{frameNumber}.png");
}Imports IronBarCode
Imports System
' TIFF files are processed similarly to regular images
' Each frame is scanned automatically
Dim multiFrameResults As BarcodeResults = BarcodeReader.Read("Multiframe.tiff")
For Each result In multiFrameResults
' Access frame-specific information
Dim frameNumber As Integer = result.PageNumber ' Frame number in TIFF
Dim barcodeValue As String = result.Text
Console.WriteLine($"Frame {frameNumber}: {barcodeValue}")
' Save individual barcode images if needed
result.BarcodeImage?.SaveAs($"barcode_frame_{frameNumber}.png")
NextImports IronBarCode
Imports System
' TIFF files are processed similarly to regular images
' Each frame is scanned automatically
Dim multiFrameResults As BarcodeResults = BarcodeReader.Read("Multiframe.tiff")
For Each result In multiFrameResults
' Access frame-specific information
Dim frameNumber As Integer = result.PageNumber ' Frame number in TIFF
Dim barcodeValue As String = result.Text
Console.WriteLine($"Frame {frameNumber}: {barcodeValue}")
' Save individual barcode images if needed
result.BarcodeImage?.SaveAs($"barcode_frame_{frameNumber}.png")
Next同じBarcodeReaderOptionsはTIFF処理にも適用され、画像フィルターや回転設定を含みます。 詳細なTIFF処理シナリオについては、画像処理チュートリアルをご覧ください。
マルチスレッド処理で処理速度を上げることができますか?
複数の文書を処理する場合、並列処理によって大きな効果が得られます。IronBarcodeは利用可能なCPUコアを自動的に活用し、最適なパフォーマンスを実現します。
using IronBarCode;
// List of documents to process - mix of formats supported
var documentBatch = new[]
{
"invoice1.pdf",
"shipping_label.png",
"inventory_sheet.tiff",
"product_catalog.pdf"
};
// Configure for batch processing
BarcodeReaderOptions batchOptions = new BarcodeReaderOptions
{
// Enable parallel processing across documents
Multithreaded = true,
// Limit threads if needed (0 = use all cores)
MaxParallelThreads = Environment.ProcessorCount,
// Apply consistent settings to all documents
Speed = ReadingSpeed.Balanced,
ExpectBarcodeTypes = BarcodeEncoding.All
};
// Process each document, tracking the source path externally
foreach (var document in documentBatch)
{
BarcodeResults results = BarcodeReader.Read(document, batchOptions);
Console.WriteLine($"\nDocument: {document}");
foreach (var barcode in results)
{
Console.WriteLine($" - {barcode.BarcodeType}: {barcode.Text}");
}
}using IronBarCode;
// List of documents to process - mix of formats supported
var documentBatch = new[]
{
"invoice1.pdf",
"shipping_label.png",
"inventory_sheet.tiff",
"product_catalog.pdf"
};
// Configure for batch processing
BarcodeReaderOptions batchOptions = new BarcodeReaderOptions
{
// Enable parallel processing across documents
Multithreaded = true,
// Limit threads if needed (0 = use all cores)
MaxParallelThreads = Environment.ProcessorCount,
// Apply consistent settings to all documents
Speed = ReadingSpeed.Balanced,
ExpectBarcodeTypes = BarcodeEncoding.All
};
// Process each document, tracking the source path externally
foreach (var document in documentBatch)
{
BarcodeResults results = BarcodeReader.Read(document, batchOptions);
Console.WriteLine($"\nDocument: {document}");
foreach (var barcode in results)
{
Console.WriteLine($" - {barcode.BarcodeType}: {barcode.Text}");
}
}Imports IronBarCode
' List of documents to process - mix of formats supported
Dim documentBatch = New String() {"invoice1.pdf", "shipping_label.png", "inventory_sheet.tiff", "product_catalog.pdf"}
' Configure for batch processing
Dim batchOptions As New BarcodeReaderOptions With {
.Multithreaded = True,
' Limit threads if needed (0 = use all cores)
.MaxParallelThreads = Environment.ProcessorCount,
' Apply consistent settings to all documents
.Speed = ReadingSpeed.Balanced,
.ExpectBarcodeTypes = BarcodeEncoding.All
}
' Process each document, tracking the source path externally
For Each document In documentBatch
Dim results As BarcodeResults = BarcodeReader.Read(document, batchOptions)
Console.WriteLine(vbLf & "Document: " & document)
For Each barcode In results
Console.WriteLine($" - {barcode.BarcodeType}: {barcode.Text}")
Next
NextImports IronBarCode
' List of documents to process - mix of formats supported
Dim documentBatch = New String() {"invoice1.pdf", "shipping_label.png", "inventory_sheet.tiff", "product_catalog.pdf"}
' Configure for batch processing
Dim batchOptions As New BarcodeReaderOptions With {
.Multithreaded = True,
' Limit threads if needed (0 = use all cores)
.MaxParallelThreads = Environment.ProcessorCount,
' Apply consistent settings to all documents
.Speed = ReadingSpeed.Balanced,
.ExpectBarcodeTypes = BarcodeEncoding.All
}
' Process each document, tracking the source path externally
For Each document In documentBatch
Dim results As BarcodeResults = BarcodeReader.Read(document, batchOptions)
Console.WriteLine(vbLf & "Document: " & document)
For Each barcode In results
Console.WriteLine($" - {barcode.BarcodeType}: {barcode.Text}")
Next
Nextこの並列アプローチは、ドキュメントを同時に処理し、マルチコアシステムでのスキャン時間を短縮します。 エンタープライズ規模のバーコード処理には、パフォーマンス最適化ガイドを探索してください。
まとめ
IronBarcodeを使用すると、複雑なバーコードスキャンを簡潔なC#コードで実装できます。在庫システム、文書処理ツール、モバイルアプリケーションなど、どのような用途でも、鮮明なデジタルバーコードから読み取りが難しい実際の撮影画像まで対応できます。
カバーされている主な機能:
- 画像からの1行バーコード読み取り
- 損傷または回転したバーコードのための高度なオプション
- 包括的なPDFとTIFF文書のスキャン
- マルチスレッドによる高性能バッチ処理
- すべての主要なバーコードフォーマットのサポート
さらなる読み物
これらのリソースでバーコード処理機能を拡張:
- バーコード生成チュートリアル - カスタムバーコードの作成
- QRコードガイド - 専門的なQRコード機能
BarcodeReaderクラスリファレンス - 完全なAPIドキュメント- トラブルシューティングガイド - 一般的な問題と解決策
ソースコードダウンロード
これらの例を自分で実行:
アプリケーションでバーコードスキャンを実装する準備は整いましたか? 無料トライアルを開始して、プロフェッショナルなバーコード読み取りを.NETプロジェクトに追加してください。
よくある質問
IronBarcodeとは何ですか?
IronBarcode は、C#でバーコードやQRコードを簡単に読み取ることができる.NETライブラリで、使いやすい機能と様々な画像品質レベルに対応する高度な機能を提供します。
IronBarcodeを使用してC#でバーコードをどのように読み取りますか?
C#でIronBarcodeを使用してバーコードを読み取るには、次の1行のコードを使用します: IronBarCode.BarcodeReader.Read("path/to/barcode.png");。このメソッドはバーコードの種類を効率的に検出し、エンコードされた情報を提供します。
IronBarcodeは1つのファイルから複数のバーコードを読み取ることができますか?
はい、IronBarcodeは複数のバーコードをPDFやマルチフレームTIFFファイルを含む単一の画像またはドキュメントから読み込むことができ、各バーコードを自動的に検出して抽出します。
IronBarcodeには、損傷したバーコードを処理するためのどのような機能がありますか?
IronBarcodeは、自動回転、AdaptiveThresholdFilterを使用した画像フィルタリング、機械学習などの高度な機能を提供し、光が悪い場合や傾いた角度のある不完全な画像からバーコードをデコードします。
.NETプロジェクトにIronBarcodeをインストールするにはどうすればいいですか?
.NETプロジェクトにIronBarcodeを簡単にインストールするには、NuGetパッケージマネージャーを使用するか、DLLファイルをダウンロードします。自動依存管理と更新のためにNuGetを使用することをお勧めします。
IronBarcodeはPDFドキュメントからのバーコードスキャンをサポートしていますか?
はい、IronBarcodeは全ページにわたるPDFドキュメントから効率的にバーコードをスキャンし、マルチスレッドをサポートしてより高速な処理を実現します。
IronBarcodeはマルチフレームTIFF画像を処理できますか?
はい、IronBarcodeはマルチフレームTIFF画像を処理でき、各フレームを自動的にスキャンしてバーコードを検索し、包括的な結果を提供します。
IronBarcodeはどのようにしてバーコードスキャンのパフォーマンスを最適化しますか?
IronBarcodeはマルチスレッディング機能を備えており、利用可能なすべてのCPUコアを使用して複数のドキュメントや画像に対してバーコードスキャンを実行することで、処理時間を短縮します。
IronBarcodeがサポートするバーコードフォーマットは何ですか?
IronBarcodeは、Code128、Code39、QRコード、Data Matrixコードなど、多様なバーコード形式をサポートしており、様々なシナリオでの多目的な応用を可能にします。
IronBarcodeでバーコード読み取りの精度を向上させる方法はありますか?
IronBarcodeの精度を向上させるには、BarcodeReaderOptionsを構成して特定の画像フィルタを使用し、自動回転を有効にし、ExpectBarcodeTypesプロパティを設定して特定のバーコードタイプに限定してスキャンすることで実現できます。
Jacob Mellorは、Iron Softwareの最高技術責任者であり、C# PDF技術を先導するビジョナリーなエンジニアです。Iron Softwareのコアコードベースの最初の開発者として、CEOのCameron Rimingtonと共に、NASA、Tesla、および世界中の政府機関を対象にサービスを提供する50人以上の企業に変革しました。