條碼快速入門
using IronBarCode;
using System.Drawing;

// Reading a barcode is easy with IronBarcode!
var resultFromFile = BarcodeReader.Read(@"file/barcode.png"); // From a file
var resultFromBitMap = BarcodeReader.Read(new Bitmap("barcode.bmp")); // From a bitmap
var resultFromImage = BarcodeReader.Read(Image.FromFile("barcode.jpg")); // From an image file
var resultFromPdf = BarcodeReader.ReadPdf(@"file/mydocument.pdf"); // From PDF use ReadPdf

// To configure and fine-tune barcode reading, utilize the BarcodeReaderOptions class
var myOptionsExample = new BarcodeReaderOptions
{
    // Choose a reading speed from: Faster, Balanced, Detailed, ExtremeDetail
    // There is a tradeoff in performance as more detail is set
    Speed = ReadingSpeed.Balanced,

    // Reader will stop scanning once a single barcode is found (if set to true)
    ExpectMultipleBarcodes = true,

    // By default, all barcode formats are scanned for
    // Specifying a subset of barcode types to search for would improve performance
    ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,

    // Utilize multiple threads to read barcodes from multiple images in parallel
    Multithreaded = true,

    // Maximum threads for parallelized barcode reading
    // Default is 4
    MaxParallelThreads = 2,

    // The area of each image frame in which to scan for barcodes
    // Specifying a crop area will significantly improve performance and avoid noisy parts of the image
    CropArea = new Rectangle(),

    // Special setting for Code39 barcodes
    // If a Code39 barcode is detected, try to read with both the base and extended ASCII character sets
    UseCode39ExtendedMode = true
};

// Read with the options applied
var results = BarcodeReader.Read("barcode.png", myOptionsExample);

// Create a barcode with one line of code
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8);

// After creating a barcode, we may choose to resize
myBarcode.ResizeTo(400, 100);

// Save our newly-created barcode as an image
myBarcode.SaveAsImage("EAN8.jpeg");

// Get the barcode as an image for further processing
var myBarcodeImage = myBarcode.Image;
NuGet 下載
PM > Install-Package BarCode
條碼快速入門

條碼快速入門

IronBarcode支持各種標準格式,從圖像文件(jpeg, png, 和 jpg)到更多程序化格式,您會希望在其中傳遞變量,如位圖。此外,它還支持外部格式比如PDF,使得IronBarcode可以無縫地整合到任何代碼庫中,為開發者提供靈活的文件格式和變數。

除了是所有檔案格式的條碼閱讀器外,IronBarcode也同時是一個條碼生成器,支援所有標準編碼和格式,例如EAN8、Code128和Code39。 設定條碼產生器只需要兩行程式碼。 IronBarcode以其低入門門檻和多種自定義選項成為所有條碼相關情境的最佳選擇。

C# 中的條碼讀取器和條碼產生器

  1. var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeEncoding.EAN8);
  2. Image myBarcodeImage = myBarcode.ToImage();
  3. myBarcode.ResizeTo(400, 100);。
  4. var resultFromFile = BarcodeReader.Read(@"file/barcode.png");。
  5. var myOptionsExample = new BarcodeReaderOptions { /* Options */ };

條碼寫入器

首先,我們匯入必要的程式庫,如 IronBarCode 和 System.Drawing,再實例化 BarcodeWriter 以創建具有格式 EAN8 的條碼,字串值為 12345。 然後我們將生成的條碼以所需格式儲存為圖像。 IronBarcode 支援將條碼創建為 Image 以及 Bitmap,有多種選項。

進階條碼寫入器

如上所見,使用IronBarcode生成條碼只需要兩行代碼,然後將其保存為文件以供日後使用。 IronBarcode通過為開發者提供大量選項以自定義條碼以適應情況進一步擴展這一點。

我們可以使用 ResizeTo 方法,並傳入高度及寬度來調整條碼圖片的大小。

條碼閱讀器

如上所述,我們首先實例化 BarcodeReader,將檔案路徑傳遞給 Read 方法,並將其儲存為變數,以便後續使用和操作條碼物件。 針對外部格式(例如 PDF) 的讀取,有特定的方法 ReadPdf; 然而,對於一般影像格式和位圖,我們會使用 Read。

條碼讀取器選項

IronBarcode允許開發者從標準文件格式中掃描條碼。 不過,有些情況下,開發人員希望微調 BarcodeReaderOptions 類別的行為,特別是當它程式化地讀取一批條碼檔案時。 這時就會用到 BarcodeReaderOptions。 IronBarcode 讓您能完全自訂化,如使用 Speed 來決定讀取速度,使用 ExpectMultipleBarcodes 來決定檔案中是否預期會有多個條碼,以及使用屬性 ExpectBarcodeTypes 來定義它們是什麼類型的條碼。 這樣一來,開發人員就可以運行多個執行緒來並行讀取多個映像中的條碼,還可以控制並行讀取時使用的執行緒數。

這些只是展示IronBarcode強大之處的一些屬性。 完整列表請參閱這份文件。

通過我們的詳細指南學習創建條碼! Read

在 GitHub 查看

準備好開始了嗎?

NuGet 下載次數 2,575,633版本:2026.11剛剛發布