如何在C#中修正條碼方向 | IronBarcode

How to Fix Barcode Orientation

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

條碼方向是指條碼在產品或文件上打印或顯示的角度。 它可以調整到不同的角度以滿足不同的佈局和設計需求。 最常見的方向是水平的,條碼從左到右對齊,這是標準和最廣泛使用的格式。 任何非零的方向度數對於庫來說都是一個挑戰,需要檢測和檢索值。 IronBarcode 提供自動方向校正功能,以檢測任何非零的條碼和 QR 碼方向。

快速入門:一行代碼自動旋轉圖像校正

以下是如何輕鬆地糾正方向:只需一行代碼使用 IronBarcode 的 AutoRotate 選項—默認啟用—即可準確讀取即使圖像旋轉的條碼。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. Copy and run this code snippet.

    var result = IronBarCode.BarcodeReader.Read("rotatedImage.png", new IronBarCode.BarcodeReaderOptions { AutoRotate = true });
  3. Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

簡化流程(5步驟)

  1. 下載 C# 庫以修正條碼方向
  2. AutoRotate 屬性設為 true
  3. 導入目標條碼和 QR 碼
  4. 使用讀取選項讀取條碼和 QR 碼
  5. 檢索得到的條碼值

條碼方向校正範例

要應用自動方向校正,請在 BarcodeReaderOptions 中將 AutoRotate 屬性設為 true。 此屬性默認設置為 true,因此您不需要做任何事情。 讀取任何非零方向的條碼圖像應該能夠正常工作。

讓我們使用下方的圖像作為我們的示例。 Download the following 20° rotation and 45° rotation sample images.

class="competitors-section__wrapper-even-1">
20° Rotation
45° Rotation

代碼

: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

在許多情況下,僅糾正旋轉可能不夠,還需要一個過濾器。 了解如何在以下文章中使用圖像過濾器:"如何使用圖像校正濾鏡。"

常見問題解答

什麼是條碼方向,為什麼重要?

條碼方向指的是條碼在產品或文檔上顯示或打印的角度。正確的方向對於準確的條碼檢測和讀取至關重要,因為非標準方向可能會使這些過程變得複雜。

如何在 .NET C# 中校正條碼方向?

您可以使用 IronBarcode 的自動方向校正功能在 .NET C# 中校正條碼方向。這涉及將 BarcodeReaderOptions 中的 AutoRotate 屬性設為 true,該屬性預設為啟用。

使用 C# 庫修復條碼方向的步驟是什麼?

要使用 C# 庫修復條碼方向,從 NuGet 下載 IronBarcode,將 AutoRotate 屬性設為 true,導入條碼和 QR 碼,使用庫讀取它們,並檢索生成的值。

我可以看看如何實現自動方向校正的示例嗎?

是的,文章提供了一個 C# 示例以演示如何使用 IronBarcode 實現自動方向校正。這涉及在條碼讀取選項中將 AutoRotate 屬性設為 true。

是否有資源可以用於測試條碼方向校正?

是的,文章提供了帶有 20° 和 45° 旋轉的樣本圖像,用於測試條碼方向校正。這些圖像可以直接從網頁下載以進行練習。

如果方向校正不夠,我應該怎麼辦?

如果僅靠方向校正不夠,您可能需要應用圖像過濾器。文章建議學習如何使用圖像校正過濾器以增強條碼讀取效果。

為什麼我需要下載用於條碼方向校正的 C# 庫?

下載像 IronBarcode 這樣的 C# 庫是實現條碼方向校正所必需的,因為它提供了必要的工具和選項,如 AutoRotate 功能,用於處理各種條碼方向。

設置 AutoRotate 屬性如何幫助條碼讀取?

在 IronBarcode 的 BarcodeReaderOptions 中將 AutoRotate 屬性設為 true 能夠啟用自動方向校正,確保條碼無論初始方向如何都能正確讀取。

Chaknith Bin
軟體工程師
Chaknith 在 IronXL 和 IronBarcode 上工作。他對 C# 和 .NET 擁有深厚的專業知識,幫助改進了軟體並支持客戶。他從用戶互動中得到的見解有助於改善產品、文檔和整體體驗。
準備好開始了嗎?
Nuget 下載 1,935,276 | 版本: 2025.11 剛剛發布