IRONSOFTWAREHOME
条形码快速入门
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;
Imports IronBarCode
Imports System.Drawing

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

' To configure and fine-tune barcode reading, utilize the BarcodeReaderOptions class
Dim myOptionsExample As New BarcodeReaderOptions With {
    ' 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
Dim results = BarcodeReader.Read("barcode.png", myOptionsExample)

' Create a barcode with one line of code
Dim 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
Dim myBarcodeImage = myBarcode.Image
NuGet Download
PM > Install-Package BarCode
条形码快速入门

条形码快速入门

IronBarcode支持多种标准格式,从图像文件(jpeg、png和jpg)到您可能希望传递变量的更程序化格式,如位图。此外,它还支持外部格式,如PDF,使IronBarcode可无缝集成到任何代码库中,为开发人员提供文件格式和变量的灵活性。

除了作为所有文件格式的条码阅读器之外,IronBarcode还兼作支持所有标准编码和格式的条码生成器,例如Code39。 设置条形码生成器只需要两行代码。 IronBarcode凭借低进入门槛和大量的定制选项,是所有与条码相关的情况的首选。

C# 中的条形码读取器和条形码生成器

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

条形码写入器

我们首先导入必要的库,如EAN8。 然后我们将生成的条形码以所需格式保存为图像。 对于此操作,有多种选项,因为IronBarcode支持创建为Bitmap的条码。

高级条码写入器

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

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

条形码阅读器

与上述相似,我们首先实例化Read方法,并将其保存为变量以供后续使用和操作条码对象。 对于如PDF的外部格式读取,有指定方法和ReadPDF; 然而,对于一般图像格式和位图,我们应使用Read

条形码读取器选项

IronBarcode允许开发人员从标准文件格式中扫描条码。 不过,有些情况下开发人员希望微调BarcodeReaderOptions方法的行为,特别是在批量程序读取条码文件时。 此时BarcodeReaderOptions派上用场。 IronBarcode让您可以完全自定义诸如ExpectBarcodeTypes。 这样一来,开发人员就可以运行多个线程来并行读取多个图像中的条形码,还可以控制并行读取时使用的线程数。

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

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

在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,422,100版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户