using IronBarCode;using IronSoftware.Drawing;using System.Collections.Generic;// Read barcode from PDF fileBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Create list for barcodesList<AnyBitmap> barcodeList = new List<AnyBitmap>();foreach (BarcodeResult barcode in result){ barcodeList.Add(barcode.BarcodeImage);}// Create multi-page TIFFAnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif");
using IronBarCode;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Read barcode from PDF file
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Create list for barcodes
List<AnyBitmap> barcodeList = new List<AnyBitmap>();
foreach (BarcodeResult barcode in result)
{
barcodeList.Add(barcode.BarcodeImage);
}
// Create multi-page TIFF
AnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif");
ImportsIronBarCodeImportsIronSoftware.DrawingImportsSystem.Collections.Generic' Read barcode from PDF filePrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Create list for barcodesPrivate barcodeList As New List(OfAnyBitmap)()For Each barcode AsBarcodeResultIn result barcodeList.Add(barcode.BarcodeImage)Next barcode' Create multi-page TIFFAnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif")
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Collections.Generic
' Read barcode from PDF file
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Create list for barcodes
Private barcodeList As New List(Of AnyBitmap)()
For Each barcode As BarcodeResult In result
barcodeList.Add(barcode.BarcodeImage)
Next barcode
' Create multi-page TIFF
AnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif")
using IronBarCode;using System;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("bc3.png");// Output barcode type to consoleforeach (BarcodeResult barcode in result){Console.WriteLine("The barcode value is " + barcode.ToString() + " and the barcode type is " + barcode.BarcodeType);}
using IronBarCode;
using System;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("bc3.png");
// Output barcode type to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine("The barcode value is " + barcode.ToString() + " and the barcode type is " + barcode.BarcodeType);
}
ImportsIronBarCodeImportsSystem' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("bc3.png")' Output barcode type to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine("The barcode value is " & barcode.ToString() & " and the barcode type is " & barcode.BarcodeType)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("bc3.png")
' Output barcode type to console
For Each barcode As BarcodeResult In result
Console.WriteLine("The barcode value is " & barcode.ToString() & " and the barcode type is " & barcode.BarcodeType)
Next barcode
Using IronBarcode,用户可以通过访问 BarcodeResult 对象的 BinaryValue 属性,获取条形码 value 的字节数组。 这使得用户能够在程序内部进一步处理BarCode value。 二进制 value 输出在处理加密数据、BarCode编码的文件附件,或与需要字节级数据处理的系统集成时尤为有用。
下面的代码片段演示了将BarCode value 作为二进制数据检索的一种用例:
using IronBarCode;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");int i = 1;foreach (BarcodeResult barcode in result){ var binaryValue = barcode.BinaryValue; var barcodeType = IronBarCode.BarcodeEncoding.QRCode; // Create QR code GeneratedBarcode generatedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType); // Export QR code generatedBarcode.SaveAsPng($"qrFromBinary{i}.png"); i++;}
using IronBarCode;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");
int i = 1;
foreach (BarcodeResult barcode in result)
{
var binaryValue = barcode.BinaryValue;
var barcodeType = IronBarCode.BarcodeEncoding.QRCode;
// Create QR code
GeneratedBarcode generatedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType);
// Export QR code
generatedBarcode.SaveAsPng($"qrFromBinary{i}.png");
i++;
}
ImportsIronBarCode' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("multiple-barcodes.png")Private i AsInteger = 1For Each barcode AsBarcodeResultIn result Dim binaryValue = barcode.BinaryValue Dim barcodeType = IronBarCode.BarcodeEncoding.QRCode ' Create QR code Dim generatedBarcode AsGeneratedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType) ' Export QR code generatedBarcode.SaveAsPng($"qrFromBinary{i}.png") i += 1Next barcode
Imports IronBarCode
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("multiple-barcodes.png")
Private i As Integer = 1
For Each barcode As BarcodeResult In result
Dim binaryValue = barcode.BinaryValue
Dim barcodeType = IronBarCode.BarcodeEncoding.QRCode
' Create QR code
Dim generatedBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType)
' Export QR code
generatedBarcode.SaveAsPng($"qrFromBinary{i}.png")
i += 1
Next barcode
using IronBarCode;using IronSoftware.Drawing;using System.Linq;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");AnyBitmap bitmap = AnyBitmap.FromFile("multiple-barcodes.png");foreach (BarcodeResult barcode in result){ PointF[] barcodePoints = barcode.Points; float x1 = barcodePoints.Select(b => b.X).Min(); float y1 = barcodePoints.Select(b => b.Y).Min(); Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!); bitmap = bitmap.Redact(rectangle, Color.Magenta); // Save the image bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png);}
using IronBarCode;
using IronSoftware.Drawing;
using System.Linq;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");
AnyBitmap bitmap = AnyBitmap.FromFile("multiple-barcodes.png");
foreach (BarcodeResult barcode in result)
{
PointF[] barcodePoints = barcode.Points;
float x1 = barcodePoints.Select(b => b.X).Min();
float y1 = barcodePoints.Select(b => b.Y).Min();
Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!);
bitmap = bitmap.Redact(rectangle, Color.Magenta);
// Save the image
bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png);
}
ImportsSystemImportsIronBarCodeImportsIronSoftware.DrawingImportsSystem.Linq' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("multiple-barcodes.png")Private bitmap AsAnyBitmap = AnyBitmap.FromFile("multiple-barcodes.png")For Each barcode AsBarcodeResultIn result Dim barcodePoints() AsPointF = barcode.Points Dim x1 AsSingle = barcodePoints.Select(Function(b) b.X).Min() Dim y1 AsSingle = barcodePoints.Select(Function(b) b.Y).Min()'INSTANT VB TODO TASK: There is no VB equivalent to the C# 'null-forgiving operator':'ORIGINAL LINE: Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!); Dim rectangle As New Rectangle(CInt(Math.Truncate(x1)), CInt(Math.Truncate(y1)), CInt(barcode.Width), CInt(barcode.Height)) bitmap = bitmap.Redact(rectangle, Color.Magenta) ' Save the image bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png)Next barcode
Imports System
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Linq
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("multiple-barcodes.png")
Private bitmap As AnyBitmap = AnyBitmap.FromFile("multiple-barcodes.png")
For Each barcode As BarcodeResult In result
Dim barcodePoints() As PointF = barcode.Points
Dim x1 As Single = barcodePoints.Select(Function(b) b.X).Min()
Dim y1 As Single = barcodePoints.Select(Function(b) b.Y).Min()
'INSTANT VB TODO TASK: There is no VB equivalent to the C# 'null-forgiving operator':
'ORIGINAL LINE: Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!);
Dim rectangle As New Rectangle(CInt(Math.Truncate(x1)), CInt(Math.Truncate(y1)), CInt(barcode.Width), CInt(barcode.Height))
bitmap = bitmap.Redact(rectangle, Color.Magenta)
' Save the image
bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png)
Next barcode
用户可以获取发现BARCODE的页码。 对于使用包含多个BarCode的多页文档,且需要了解文档中BarCode位置以便进行后续处理的用户而言,这是一项非常有用的功能。 在从 PDF 文档中读取 BarCode 或在 Enterprise 应用程序中处理批量文档时,此功能至关重要。
请参阅以下代码片段:
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Output page number to consoleforeach (BarcodeResult barcode in result){Console.WriteLine("The barcode value " + barcode.ToString() + " is found on page number " + barcode.PageNumber);}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Output page number to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine("The barcode value " + barcode.ToString() + " is found on page number " + barcode.PageNumber);
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Output page number to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine("The barcode value " & barcode.ToString() & " is found on page number " & barcode.PageNumber)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Output page number to console
For Each barcode As BarcodeResult In result
Console.WriteLine("The barcode value " & barcode.ToString() & " is found on page number " & barcode.PageNumber)
Next barcode
上方的代码片段展示了一个典型用例:用户需要程序返回多页PDF文档中BARCODE的value及其对应的页码。 该代码使用 BarcodeReader.ReadPdf() 方法读取多页 PDF 文档中的 BarCode,该方法会返回一个 BarcodeResults 对象,其中存储了文档中找到的每个 BarcodeResult。 我们使用循环遍历对象中的每个项,以获取BarCode的 value 以及发现BarCode的页码。 除此用例外,用户还可利用此属性进行调试,以确认文档中的所有BarCode是否均已被读取。
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Output page orientation and rotation to consoleforeach (BarcodeResult barcode in result){Console.WriteLine(barcode.Value);Console.WriteLine(barcode.PageOrientation);Console.WriteLine(barcode.Rotation);}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Output page orientation and rotation to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine(barcode.Value);
Console.WriteLine(barcode.PageOrientation);
Console.WriteLine(barcode.Rotation);
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Output page orientation and rotation to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine(barcode.Value)Console.WriteLine(barcode.PageOrientation)Console.WriteLine(barcode.Rotation)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Output page orientation and rotation to console
For Each barcode As BarcodeResult In result
Console.WriteLine(barcode.Value)
Console.WriteLine(barcode.PageOrientation)
Console.WriteLine(barcode.Rotation)
Next barcode
上方的代码片段已结合附带的示例 PDF 文件运行,以证明用户可以通过获取 pageOrientation 和 BarCode rotation,分别获取页面方向和 BarCode 旋转角度。 此功能主要用于调试目的。
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("barcodestamped3.pdf");// Output text value to consoleforeach (BarcodeResult barcode in result){Console.WriteLine(barcode.Value);Console.WriteLine(barcode.Text);Console.WriteLine(barcode.ToString());}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("barcodestamped3.pdf");
// Output text value to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine(barcode.Value);
Console.WriteLine(barcode.Text);
Console.WriteLine(barcode.ToString());
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("barcodestamped3.pdf")' Output text value to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine(barcode.Value)Console.WriteLine(barcode.Text)Console.WriteLine(barcode.ToString())Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("barcodestamped3.pdf")
' Output text value to console
For Each barcode As BarcodeResult In result
Console.WriteLine(barcode.Value)
Console.WriteLine(barcode.Text)
Console.WriteLine(barcode.ToString())
Next barcode
从上面的代码片段可以看出,用户只需几行代码,即可使用 IronBarcode 读取图像中的条形码。 遍历 BarcodeResults 方法返回的 BarcodeReader.Read() 后,我们将获取 Value 和 Text 属性的结果,并调用 BarcodeResult.ToString() 方法,以展示所有这些操作均返回相同的 value。
using IronBarcode,您可以在一行中读取条形码: var result = IronBarCode.BarcodeReader.Read('input.png'); 这样您就可以立即通过 result[0].Value 和 result[0].BarcodeType 访问条形码的值和类型。
IronBarcode 为每个检测到的条码提供坐标数据,包括 x 和 y 位置以及高度和宽度尺寸。这些属性可通过 BarcodeResult 对象访问,以实现精确的条形码位置跟踪。
文本属性和值属性有什么区别?
在 IronBarcode 中,Text 和 Value 属性都包含条码的数据内容。这些属性是 BarcodeResult 对象的一部分,可交替使用以检索解码后的条形码信息。
我能否确定条形码是在哪一页上找到的?
是的,IronBarcode 在 BarcodeResult 对象中包含 PageNumber 属性,允许您准确识别多页文档或 PDF 中的哪一页包含每个检测到的条码。
如何识别检测到的 BarCode 类型?
IronBarcode 的 BarcodeResult 对象中的 BarcodeType 属性可识别检测到的特定条码格式(如 QR 码、Code 128 等),从而可在应用程序中进行特定格式处理。
What kind of applications benefit from using IronBarcode's output data formats?
Applications in inventory management, document processing, and quality control greatly benefit from IronBarcode's diverse data formats as they offer extensive barcode data processing options.
Can IronBarcode read barcodes from multipage PDF documents?
Yes, IronBarcode can read barcodes from multipage PDF documents using methods like `BarcodeReader.ReadPdf()`, which also informs about the page number on which each barcode is found.