Code 39バーコードをC#で迅速かつ簡単に読み取る
IronBarcode を使用すると、BarcodeReaderOptions クラスで BarcodeEncoding.Code39 を指定し、必要に応じてUseCode39ExtendedMode を有効にしてASCII文字セット全体をサポートすることで、C# で標準および拡張コード39バーコードの読み取りを簡素化できます。
Code 39 は、在庫管理、物流、および産業用アプリケーションで広く使用されている汎用バーコード形式です。 Code 39 バーコードは長さを変えることができるため、さまざまな使用ケースに柔軟に対応できます。
オリジナルの標準コード39は、大文字(A-Z)、数字(0-9)、およびいくつかの特殊文字(スペース、-、$、+、%、.)をエンコードします。 これは基本的なIDには有効ですが、最近のアプリケーションでは128のASCII文字すべてをエンコードする必要があることがよくあります。 Code 39 Extended 仕様はこのニーズに対応します。
このガイドでは、IronBarcodeを使用した標準および拡張Code 39の読み取り方法を説明します。 在庫管理システムの構築、出荷の追跡、産業用バーコードの処理など、IronBarcodeは信頼性の高いCode 39読み取り機能を提供します。 バーコード読み取り機能の完全な概要については、包括的なバーコードクイックスタートガイドをご覧ください。
クイックスタート: C#でCode 39バーコードを読み取る
IronBarcode の BarcodeReader を使用して、1行のコードで画像から Code 39 バーコードをデコードします。 すぐに開始しましょう - エンコーディングタイプを指定し、画像を渡して結果を読み取ります。
-
1IronBarcode を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
using System.Linq; IronBarCode.BarcodeReader.Read("code39.png", new IronBarCode.BarcodeReaderOptions { ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.Code39 }).First().ToString();Dim result As String = IronBarCode.BarcodeReader.Read("code39.png", New IronBarCode.BarcodeReaderOptions With {.ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.Code39}).First().ToString()Dim result As String = IronBarCode.BarcodeReader.Read("code39.png", New IronBarCode.BarcodeReaderOptions With {.ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.Code39}).First().ToString() -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronBarcodeを使い始めるには、無料トライアルをお試しください。
C#でCode 39バーコードを読み取る方法
- Code39 バーコードを読み取るための IronBarcode C# ライブラリをダウンロードします。
- 新しい
BarcodeReaderOptionsを初期化します。 - オプションで
BarcodeEncoding.Code39を指定してください。 ReadでCode 39バーコードを読み取ります。- 結果を検証し、コンソールに出力します。
標準のCode 39バーコードはどのようにして読み取りますか?
IronBarcodeでCode 39バーコードを読むのは簡単です。 まず、新しい BarcodeReaderOptions を初期化し、バーコードタイプを BarcodeEncoding.Code39 と指定します。 これは、どのような BarCode フォーマットを探すべきかを正確に伝えることで、リーダーを最適化します。
次に、Read メソッドを使用してバーコード画像とオプションをパラメータとして渡し、バーコードを読み取ります。 次に、結果コレクションを繰り返し処理し、各 BarCode の文字列値をコンソールに出力します。 より高度な設定については、バーコードリーダー設定の詳細ガイドを探索してください。
標準のCode 39バーコードはどのような見た目ですか?
この画像には標準の Code 39 バーコードが含まれています。 バーコードが、エンコードされた値をバーと人間が読めるテキストの両方で表示していることに注目してください。 この二重表現は、産業および物流アプリケーションにおけるCode 39バーコードの典型です。

標準のCode 39を読み取るにはどのようなコードが必要ですか?
using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Tell the reader to only look for Code 39.
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the image file using the specified options
var results = BarcodeReader.Read("code39.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString());
}using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Tell the reader to only look for Code 39.
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the image file using the specified options
var results = BarcodeReader.Read("code39.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString());
}Imports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the image file using the specified options
Dim results = BarcodeReader.Read("code39.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString())
NextImports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the image file using the specified options
Dim results = BarcodeReader.Read("code39.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString())
Next予想される BarCode タイプを指定することで、読み取り性能が大幅に向上します。 IronBarcodeは他のバーコード形式を探す時間を無駄にしないので、特に大きな画像セットのバッチ処理に役立ちます。 読み取り速度オプションガイドを使ってバーコード読み取り性能を最適化する方法を学びましょう。
どのような出力が期待できますか?

コンソール出力は、Code 39バーコードから正常にデコードされた値「ABC-1234」を示しています。 終了コード0は、エラーなしで正常に実行されたことを確認します。 本番アプリケーションでは、BarCodeが認識されない場合の適切なエラー処理を実装してください。 問題が発生した場合は、認識されないバーコードに関するトラブルシューティングガイドをご覧ください。
拡張Code 39バーコードをどのようにして読み取りますか?
拡張コード39バーコードの読み取りは、標準コード39と同様のプロセスに従います。主な違いは、UseCode39ExtendedMode プロパティを true に設定することです。
この設定により、IronBarcodeは特殊文字のペア(例:+T、%O)を解釈し、対応するASCII文字(例:t、!)にデコードします。拡張コード39は、標準セット以外の文字を表すために2文字のシーケンスを使用します。 このため、BarCodeは若干長くなりますが、小文字、追加の句読点、および制御文字のエンコードが可能になります。
拡張Code 39はいつ使用すべきですか?
拡張Code 39は、アプリケーションで次の内容をエンコードする必要がある場合に最適です。
- 大文字と小文字の混在したテキスト
- @、#、&、!、?などの特殊文字
- データ伝送用制御文字
- 完全なASCII文字セットのサポート
一般的なアプリケーションには、医療システム、文書追跡、リッチデータエンコーディングを必要とする高度な在庫管理などがあります。
拡張Code 39バーコードはどのような見た目ですか?
この画像には拡張コード 39 バーコードが含まれています。 値 Test-Data! には小文字の文字や感嘆符が含まれており、これらは完全な ASCII セットでのみ使用可能であり、拡張モードが必要です。

拡張Code 39のためにどのようなコードが必要ですか?
using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Enable extended Code 39 mode
UseCode39ExtendedMode = true,
// Specify that we are expecting Code 39 barcodes
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the extended code 39 image
var results = BarcodeReader.Read("code39extended.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString());
}using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Enable extended Code 39 mode
UseCode39ExtendedMode = true,
// Specify that we are expecting Code 39 barcodes
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the extended code 39 image
var results = BarcodeReader.Read("code39extended.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString());
}Imports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.UseCode39ExtendedMode = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the extended code 39 image
Dim results = BarcodeReader.Read("code39extended.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString())
NextImports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.UseCode39ExtendedMode = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the extended code 39 image
Dim results = BarcodeReader.Read("code39extended.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString())
Next拡張モードでどのような出力を期待できますか?

高度な Code 39 読み取り技術
複数のバーコードの処理
IronBarcodeは、1つの画像内の複数のCode 39バーコードを自動的に検出し、読み取ります。 Read メソッドは、各バーコードを個別に処理できる結果のコレクションを返します。 バーコードのシートや複雑なドキュメントを扱うアプリケーションの場合、複数のバーコードを読み取るガイドをご覧ください。
質の悪い画像への対処
Code 39 バーコードは、色あせた印刷物、斜めの角度、低解像度のスキャンなど、理想的でない状態で表示されることがあります。 IronBarcode には、読み取り精度を大幅に向上させる強力な画像補正フィルターが含まれています:
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.Code39,
UseCode39ExtendedMode = true,
// Apply image correction filters
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter(),
new BrightnessFilter()
}
};BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.Code39,
UseCode39ExtendedMode = true,
// Apply image correction filters
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter(),
new BrightnessFilter()
}
};Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Code39,
.UseCode39ExtendedMode = True,
' Apply image correction filters
.ImageFilters = New ImageFilterCollection() From {
New SharpenFilter(),
New ContrastFilter(),
New BrightnessFilter()
}
}Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Code39,
.UseCode39ExtendedMode = True,
' Apply image correction filters
.ImageFilters = New ImageFilterCollection() From {
New SharpenFilter(),
New ContrastFilter(),
New BrightnessFilter()
}
}パフォーマンス最適化
大量の BarCode 読み取りアプリケーションについては、以下の最適化戦略を検討してください:
- 正確なバーコードタイプを指定する - 不要なスキャンを避けるために
ExpectBarcodeTypesを常に設定します。 - 適切な読み取り速度を使用する - ニーズに基づいて速度と精度のバランスを取ります
- 画像を並行して処理する - バッチ処理のためにマルチスレッドを活用します
- 画像を事前処理する - パフォーマンスを維持するために、必要な場合にのみ補正を適用します。
まとめ
IronBarcodeはC#でのCode 39バーコードの読み取りを、標準または拡張フォーマットを問わず簡素化します。 主な手順は以下のとおりです:
これらの基礎があれば、Code 39 バーコード読み取りを .NET アプリケーションに統合する準備が整います。 完全な API ドキュメントと追加のバーコード形式については、包括的な API リファレンスをご覧ください。 Code 39 に特化した実用例については、専用の Code 39 チュートリアルをご覧ください。
よくある質問
C# で標準 Code 39 バーコードをどのように読み取りますか?
C# で標準 Code 39 バーコードを読み取るには、IronBarcodeライブラリを使用します。BarcodeReaderOptions を初期化し、BarcodeEncoding.Code39 を指定して、Read メソッドをバーコード画像と共に使用してください。
標準 Code 39 バーコードと拡張 Code 39 バーコードの違いは何ですか?
標準 Code 39 は大文字、数字、一部の特殊文字をエンコードします。拡張 Code 39 は、標準セット外の文字を表現するために +T や %O のような文字ペアを使用して、完全な ASCII セットをサポートします。
Code 39 バーコードの一般的な使用例は何ですか?
Code 39 バーコードは、在庫管理、物流、産業用途において、可変の長さと基本的な ID エンコーディングの柔軟性のために一般的に使用されます。
IronBarcode は品質の悪いバーコード画像をどのように処理しますか?
IronBarcode には、品質の悪いバーコード画像の読取精度を向上させるためのシャープ化やコントラスト調整といった画像補正フィルターが含まれています。
C# で拡張 Code 39 バーコードを読み取るために何をする必要がありますか?
拡張 Code 39 バーコードを読み取るには、IronBarcode の BarcodeReaderOptions の中で UseCode39ExtendedMode を有効にし、完全な ASCII 文字セットをデコードできるようにします。
高ボリュームアプリケーションでバーコード読み取り性能を最適化する方法は?
高ボリュームアプリケーションでは、ExpectBarcodeTypes を設定してスキャンを Code 39 に限定し、適切な読み取り速度を使用し、画像を並列処理して性能を向上させます。
IronBarcode は1つの画像から複数のバーコードを読み取れますか?
はい、IronBarcode は Read メソッドを使用して1つの画像から複数の Code 39 バーコードを検出し、読み取ることができ、その結果のコレクションを返します。
拡張 Code 39 バーコードを読み取った際にどのような出力が期待できますか?
拡張 Code 39 バーコードを読み取るとき、コンソールには小文字や特殊文字を含む完全にデコードされた ASCII 文字列が表示されることを期待してください。
なぜ拡張 Code 39 バーコードを使用する必要があるかもしれないのですか?
拡張 Code 39 は、大文字と小文字が混在するテキスト、特殊文字、または制御文字をエンコードする場合に便利であり、医療や文書追跡などの詳細なデータエンコーディングを必要とするアプリケーションに最適です。
`BarcodeReaderOptions` の IronBarcode における役割は何ですか?
BarcodeReaderOptions は、バーコードの種類や拡張モードのような設定を指定し、予想される入力を構成して追加機能を有効化することで読取プロセスを最適化します。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。