C#でバーコードの向きを修正する方法
IronBarcodeは、組み込みのAutoRotate機能を使用して、バーコードが傾いたり回転した画像からでも正確なバーコード読み取りを保証しながら、どの角度でもバーコードを検出して読み取ることでバーコードの向きを自動的に補正します。
バーコードの向きとは、製品や文書に印刷または表示される際の角度を指します。 さまざまなレイアウトやデザイン要件に合わせて、異なる角度に調整できます。 最も一般的な向きは水平で、これはバーコードが左から右に配置されるという標準で最も広く使われている形式です。 非ゼロの向きの角度は、ライブラリが値を検出して取得するための課題を引き起こします。 IronBarcodeは、バーコードとQRコードのために非ゼロの向きを自動検出して修正します。
クイックスタート:1行での自動回転画像補正IronBarcodeのAutoRotateオプション(デフォルトで有効)を使用して、画像が回転していてもバーコードを正確に読み取るために、どれほど簡単に向きを補正できるかを示しています。
-
1Install IronBarcode with NuGet Package Manager
-
2このコード スニペットをコピーして実行します。
var result = IronBarCode.BarcodeReader.Read("rotatedImage.png", new IronBarCode.BarcodeReaderOptions { AutoRotate = true });C# -
3実際の環境でテストするためにデプロイする
今日プロジェクトで IronBarcode を使い始めましょう無料トライアル
最小限のワークフロー(5ステップ)
- バーコードの向きを修正するためのC#ライブラリをダウンロードする
AutoRotateプロパティをtrueに設定します。- ターゲットのバーコードとQRコードをインポート
- 読み取りオプションでバーコードとQRコードを読む
- 結果のバーコードの値を取得
アプリケーションの BarCode の向きを修正するにはどうすればよいですか?
自動方向補正を適用するには、AutoRotateプロパティをtrueに設定します。 このプロパティはデフォルトでtrueに設定されているため、何もする必要はありません。 非ゼロ向きのバーコード画像の読み取りは自動で機能するはずです。
このAutoRotate機能は、QRコード、データマトリックス、および伝統的な線形バーコードを含むさまざまなバーコードフォーマットで作業する際に特に便利です。 画像から BarCode を読み取る場合でも、PDFドキュメントからスキャンする場合でも、向きの補正は信頼できる結果を保証します。
以下の画像をサンプルとして使用しましょう。 次の20°回転と45°回転のサンプル画像をダウンロードしてください。

20°回転

45°回転
自動回転を実装するにはどのようなコードが必要ですか?
using IronBarCode;
using System;
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Turn on auto rotation in ML detection
AutoRotate = true,
};
var results = BarcodeReader.Read("rotate20.png", myOptionsExample);
// Print out the value
Console.WriteLine(results[0].Value);Imports IronBarCode
Imports System
Private myOptionsExample As New BarcodeReaderOptions() With {.AutoRotate = True}
Private results = BarcodeReader.Read("rotate20.png", myOptionsExample)
' Print out the value
Console.WriteLine(results(0).Value)AutoRotate 機能は、バーコードの方向を自動的に検出するための高度な機械学習アルゴリズムを利用します。 これは、単一の画像内の複数の BarCode を扱う場合や、向きが異なる画像のバッチを処理する場合に特に価値があります。
さまざまな回転角度を扱う
IronBarcodeの方向補正は様々な回転角度をシームレスに処理します。 異なる回転角度で BarCode を読み取る例を示します:
using IronBarCode;
using System;
using System.Collections.Generic;
// Process multiple rotated images
var rotatedImages = new List<string> { "rotate20.png", "rotate45.png", "rotate90.png" };
var options = new BarcodeReaderOptions
{
AutoRotate = true,
// Combine with other reading optimizations
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = false
};
foreach (var imagePath in rotatedImages)
{
var results = BarcodeReader.Read(imagePath, options);
if (results.Length > 0)
{
Console.WriteLine($"Image: {imagePath} - Barcode Value: {results[0].Value}");
Console.WriteLine($"Barcode Type: {results[0].BarcodeType}");
Console.WriteLine($"Barcode Rotation: {results[0].Rotation}");
}
}
パフォーマンスの考慮事項
AutoRotate はデフォルトで有効になっていますが、そのパフォーマンスに及ぼす影響を理解することで、バーコード読み取りのワークフローを最適化するのに役立ちます。 この機能はIronBarcodeの読み取り速度オプションと効率的に連動し、アプリケーションのニーズに応じて精度とパフォーマンスのバランスをとることができます。
高速処理を必要とするアプリケーションには、AutoRotateと他の最適化技術を組み合わせることができます:
var fastReadOptions = new BarcodeReaderOptions
{
AutoRotate = true,
Speed = ReadingSpeed.Faster,
// Specify expected barcode types to improve performance
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
// Define crop region if barcode location is predictable
CropArea = new System.Drawing.Rectangle(100, 100, 300, 300)
};Dim fastReadOptions As New BarcodeReaderOptions With {
.AutoRotate = True,
.Speed = ReadingSpeed.Faster,
' Specify expected barcode types to improve performance
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
' Define crop region if barcode location is predictable
.CropArea = New System.Drawing.Rectangle(100, 100, 300, 300)
}画像補正機能との統合
IronBarcode の画像訂正フィルターとAutoRotateはシームレスに連携します。 回転している画質の悪い画像を扱う場合、複数の補正をかけることができます:
var advancedOptions = new BarcodeReaderOptions
{
AutoRotate = true,
// Apply additional image corrections
ImageFilters = new ImageFilterCollection
{
new AdaptiveThresholdFilter(),
new BrightnessFilter(1.2f),
new ContrastFilter(1.5f)
}
};
var results = BarcodeReader.Read("low-quality-rotated-barcode.jpg", advancedOptions);Imports System
Dim advancedOptions As New BarcodeReaderOptions With {
.AutoRotate = True,
' Apply additional image corrections
.ImageFilters = New ImageFilterCollection From {
New AdaptiveThresholdFilter(),
New BrightnessFilter(1.2F),
New ContrastFilter(1.5F)
}
}
Dim results = BarcodeReader.Read("low-quality-rotated-barcode.jpg", advancedOptions)方向修正のベストプラクティス
- デフォルトの動作:
AutoRotateはデフォルトで有効になっているため、通常、明示的に設定しなくても、以前に無効化したり、確実に有効にしたい場合を除いては必要ありません。
2.クロップリージョンとの組み合わせ:パフォーマンスを向上させるためにクロップ領域を使用する場合、クロップ領域が回転した BarCode を収容するのに十分な大きさであることを確認してください。
-
マルチスレッド処理:
AutoRotateはスレッドセーフであり、非同期およびマルチスレッド操作と良好に動作するため、高ボリュームのバーコード処理アプリケーションに適しています。 -
フォーマット特定の考慮事項:
AutoRotateは、すべてのサポートされているバーコードフォーマットで動作しますが、PDF417やデータマトリックスのような一部のフォーマットでは、さらにフォーマット特定のオプションが役立つ可能性があります。
多くの場合、回転の修正は十分ではなく、フィルタが必要となることがあります。 以下の記事で、画像フィルタの使い方を学んでください:"画像補正フィルターの使い方".
よくある質問
C# アプリケーションで回転した BarCode 画像を修正するにはどうすればよいですか?
IronBarcodeは内蔵のAutoRotate機能を使って回転したバーコード画像を自動的に修正します。BarCodeReaderOptionsでAutoRotateをtrueに設定するだけで(デフォルトで有効になっています)、ライブラリは手動で回転させることなく、あらゆる角度のバーコードを検出し読み取ります。
どのようなバーコードの向きを自動的に修正できますか?
IronBarcodeのAutoRotate機能は、20°、45°、90°、180°、270°の回転を含む、0度以外の向きを検出して修正することができます。この機能は、QRコード、データマトリックス、従来のリニアバーコードを含む様々なバーコードフォーマットで動作します。
傾いた BarCode を処理するために特別なコードを書く必要がありますか?
特別なコードは必要ありません。IronBarcodeのAutoRotateプロパティはデフォルトで有効になっているため、すぐに向きの修正が可能です。必要なコードは1行だけです: var result = IronBarCode.BarcodeReader.Read("rotatedImage.png");
オリエンテーション補正はPDF文書でも可能ですか?
IronBarcodeの自動回転機能は、画像だけでなくPDFドキュメントからバーコードをスキャンする際にもシームレスに機能します。向きの補正は、ソース形式に関係なく信頼性の高い結果を保証します。
自動オリエンテーション検出の原動力となる技術は何ですか?
IronBarcodeは高度な機械学習アルゴリズムを使用して、バーコードの向きを自動的に検出します。このインテリジェントなアプローチにより、傾いたり回転したりした画像からでも、手動で操作することなくバーコードを正確に読み取ることができます。
Is the AutoRotate feature in IronBarcode thread-safe?
Yes, the AutoRotate feature is thread-safe and is compatible with asynchronous and multithreaded operations, making it suitable for high-volume barcode processing applications.
What should I consider when using crop regions with the AutoRotate feature?
When using crop regions with AutoRotate, ensure that the crop area is large enough to accommodate the rotated barcode. This helps improve performance without compromising the accuracy of barcode detection.
Can I improve barcode reading from poor quality images using IronBarcode?
Yes, IronBarcode offers image correction features, such as Adaptive Threshold, Brightness, and Contrast filters, which can be used alongside AutoRotate to improve the reading of poor quality and rotated images.
How does IronBarcode handle different barcode formats with the AutoRotate feature?
IronBarcode's AutoRotate feature supports various barcode formats, including QR codes, Data Matrix, and traditional linear barcodes. For some formats like PDF417, additional format-specific options may enhance readability.
Is there any need to manually activate the AutoRotate feature in IronBarcode?
Typically, there is no need to manually activate the AutoRotate feature as it is enabled by default. You would only need to set it explicitly if it has been previously disabled or if you want to ensure its activation.

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。