条形码快速入门
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 来创建字符串值为 12345 格式为 EAN8 的条码。 然后我们将生成的条形码以所需格式保存为图像。 有多种选项可以选择,因为 IronBarcode 支持将条码创建为 Image 以及 Bitmap。

高级条码写入器

如上所见,使用IronBarcode生成条码只需两行代码,并保存为文件以供日后使用。 IronBarcode进一步扩展了这一点,为开发人员提供了大量的选项以根据情况定制条码。

我们可以使用ResizeTo方法,并传入高度和宽度以调整条形码图像的大小。

条形码阅读器

与上述类似,我们首先实例化 BarcodeReader,将文件路径传递至 Read 方法,并将其保存为一个变量以供后续使用和操作条码对象。 有专门的方法用于读取外部格式,例如以ReadPdf读取PDF; 然而,对于一般图像格式和位图,我们会使用Read。

条形码读取器选项

IronBarcode允许开发人员从标准文件格式中扫描条码。 然而,也有一些情况,开发人员希望微调BarcodeReaderOptions类的行为,特别是在程序批量读取条形码文件的情况下。 这时就用到了BarcodeReaderOptions。 IronBarcode 允许您完全自定义例如通过 Speed 控制读取速度、通过 ExpectMultipleBarcodes 判断文件中是否预期有多个条码,以及通过属性 ExpectBarcodeTypes 确定条码的类型。 这样一来,开发人员就可以运行多个线程来并行读取多个图像中的条形码,还可以控制并行读取时使用的线程数。

这些只是展示IronBarcode功能的某些属性。 完整列表请参阅此处的文档。

通过我们的详细指南学习创建条形码! Read

在GitHub上查看

准备开始了吗?

NuGet 下载量 2,564,559版本:2026.11刚刚发布