C#でバーコードの向きを修正する方法 | IronBarcode

C#でバーコードの向きを修正する方法</#35;

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcodeは、組み込みのAutoRotate機能を使用してバーコードの向きを自動的に補正します。この機能は、手動で画像を回転させることなく、あらゆる角度のバーコードを検出して読み取るため、傾いたり回転したりした画像からでも正確なバーコード読み取りを保証します。

バーコードの向きとは、製品や文書に印刷または表示される際の角度を指します。 さまざまなレイアウトやデザイン要件に合わせて、異なる角度に調整できます。 最も一般的な向きは水平で、これはバーコードが左から右に配置されるという標準で最も広く使われている形式です。 非ゼロの向きの角度は、ライブラリが値を検出して取得するための課題を引き起こします。 IronBarcodeは、バーコードとQRコードのために非ゼロの向きを自動検出して修正します。

クイックスタート:1行での自動回転画像補正

向きを修正するのはこれほど簡単です。IronBarcodeのAutoRotateオプション(デフォルトで有効)を1行のコードで指定するだけで、画像が回転していてもBARCODEを正確に読み取ることができます。

  1. IronBarcode をNuGetパッケージマネージャでインストール

    PM > Install-Package BarCode
  2. このコード スニペットをコピーして実行します。

    var result = IronBarCode.BarcodeReader.Read("rotatedImage.png", new IronBarCode.BarcodeReaderOptions { AutoRotate = true });
  3. 実際の環境でテストするためにデプロイする

    今日プロジェクトで IronBarcode を使い始めましょう無料トライアル

    arrow pointer

アプリケーションの BarCode の向きを修正するにはどうすればよいですか?

自動方向補正を適用するには、BarcodeReaderOptionsプロパティをtrueに設定してください。 このプロパティはデフォルトでtrueに設定されているため、何もする必要はありません。 非ゼロ向きのバーコード画像の読み取りは自動で機能するはずです。

AutoRotate 機能は、QRコード、データマトリックス、従来の線形BARCODEなど、さまざまなBARCODE形式を扱う際に特に役立ちます。 画像から BarCode を読み取る場合でも、PDFドキュメントからスキャンする場合でも、向きの補正は信頼できる結果を保証します。

以下の画像をサンプルとして使用しましょう。 Download the following 20° rotation and 45° rotation sample images.

Barcode rotated 20 degrees clockwise showing vertical stripes at an angle for orientation testing
Barcode rotated 45 degrees showing diagonal orientation requiring correction

自動回転を実装するにはどのようなコードが必要ですか?

:path=/static-assets/barcode/content-code-examples/how-to/image-orientation-correct-autorotate.cs
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)
$vbLabelText   $csharpLabel

AutoRotate 機能は、高度な機械学習アルゴリズムを活用して、BARCODEの向きを自動的に検出します。 これは、単一の画像内の複数の 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($"Rotation Applied: {results[0].WasRotated}");
    }
}
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($"Rotation Applied: {results[0].WasRotated}");
    }
}
Imports IronBarCode
Imports System
Imports System.Collections.Generic

' Process multiple rotated images
Dim rotatedImages As New List(Of String) From {"rotate20.png", "rotate45.png", "rotate90.png"}
Dim options As New BarcodeReaderOptions With {
    .AutoRotate = True,
    ' Combine with other reading optimizations
    .Speed = ReadingSpeed.Balanced,
    .ExpectMultipleBarcodes = False
}

For Each imagePath In rotatedImages
    Dim results = BarcodeReader.Read(imagePath, options)
    If results.Length > 0 Then
        Console.WriteLine($"Image: {imagePath} - Barcode Value: {results(0).Value}")
        Console.WriteLine($"Barcode Type: {results(0).BarcodeType}")
        Console.WriteLine($"Rotation Applied: {results(0).WasRotated}")
    End If
Next
$vbLabelText   $csharpLabel

パフォーマンスの考慮事項

AutoRotateはデフォルトで有効になっていますが、そのパフォーマンスへの影響を理解することで、BarCode読み取りワークフローを最適化できます。 この機能は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)
};
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)
}
$vbLabelText   $csharpLabel

画像補正機能との統合

AutoRotate は、IronBarcode の画像補正フィルターとシームレスに連携します。 回転している画質の悪い画像を扱う場合、複数の補正をかけることができます:

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);
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)
$vbLabelText   $csharpLabel

方向修正のベストプラクティス

  1. デフォルトの動作: AutoRotateはデフォルトで有効になっているため、以前に無効にした場合や、確実に有効にしたい場合を除き、通常は明示的に設定する必要はありません。

2.クロップリージョンとの組み合わせ:パフォーマンスを向上させるためにクロップ領域を使用する場合、クロップ領域が回転した BarCode を収容するのに十分な大きさであることを確認してください。

  1. マルチスレッド処理: AutoRotate はスレッドセーフであり、非同期およびマルチスレッド操作と良好に連携するため、大量の BarCode 処理アプリケーションに適しています。

  2. フォーマット固有の考慮事項AutoRotateはサポートされているすべてのBARCODEフォーマットに対応していますが、PDF417やData Matrixなどの一部のフォーマットでは、フォーマット固有の追加オプションを利用するとより効果的である場合があります。

多くの場合、回転の修正は十分ではなく、フィルタが必要となることがあります。 以下の記事で、画像フィルタの使い方を学んでください:"画像補正フィルターの使い方".

よくある質問

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は高度な機械学習アルゴリズムを使用して、バーコードの向きを自動的に検出します。このインテリジェントなアプローチにより、傾いたり回転したりした画像からでも、手動で操作することなくバーコードを正確に読み取ることができます。

IronBarcodeをバーコード操作に使用するメリットは何ですか?

IronBarcodeは、統合の容易さ、多数のバーコード形式サポート、高品質の画像生成、強力な読み取り能力などのメリットを提供し、C#での総合的なバーコード操作ツールとなります。

IronBarcodeはバーコードの外観カスタマイズをサポートしていますか?

はい、IronBarcodeはカラー、サイズ、テキスト注釈を含むバーコードの外観に関する詳細なカスタマイズオプションを提供し、特定のデザイン要件に合わせて調整が可能です。

IronBarcodeはビジネスプロセスの効率向上にどのように役立ちますか?

IronBarcodeは迅速かつ正確なバーコード生成と読み取りを可能にし、手動データ入力エラーの減少、在庫および資産追跡の改善などにより、ビジネスプロセスの効率を向上させます。

プロジェクトにIronBarcodeを実装するために必要なプログラミングスキルは何ですか?

IronBarcodeをプロジェクトに実装するためには、C#プログラミングの基本的な知識があれば十分で、開発者をガイドするための簡単なメソッドと包括的なドキュメントが提供されています。

IronBarcodeは小規模プロジェクトと大規模エンタープライズアプリケーションの両方に適していますか?

IronBarcodeはスケーラブルかつ多用途に設計されており、小規模プロジェクトおよび強力なバーコードソリューションを必要とする大規模エンタープライズアプリケーションの両方に適しています。

カーティス・チャウ
テクニカルライター

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

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 2,240,258 | バージョン: 2026.5 just released
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package BarCode
サンプルを実行する 文字列が BarCode になるのを見る。