# How to Output Data Formats in C# with IronBarcode
IronBarcode provides multiple output formats from barcode reads including `BarcodeImage`, `BarcodeType`, `BinaryValue`, coordinates, dimensions, page numbers, orientation, text and value properties. These formats enable processing barcode data programmatically for various use cases.
Instead of simply reading the barcode and printing values in the console, IronBarcode offers much more. It provides several output formats that pave the way for users to process read results. These formats include properties such as barcode image, barcode type, `BinaryValue`, coordinates, height, width, page number, barcode, page orientation, `text`, and `value`.
Users can manipulate these properties further within the program. Let's explore how to use these properties and use cases where they can be helpful.
*as-heading:2(Quickstart: Read Barcode Value and Type in One Line)*
This example shows how to read a barcode from an image using IronBarcode - one line to load, then immediately print the barcode's value and type. Perfect for getting started fast. For more comprehensive examples, check out the [Barcode Quickstart guide](https://ironsoftware.com/csharp/barcode/examples/barcode-quickstart/).
```cs
:title=Grab Barcode Text & Type Instantly
var result = IronBarCode.BarcodeReader.Read("input.png");
Console.WriteLine($"Value: {result[0].Value}, Type: {result[0].BarcodeType}");
```
<div class="hsg-featured-snippet">
<h3>Minimal Workflow (5 steps)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/BarCode/">Download the C# library for reading barcodes</a></li>
<li>Prepare the PDF and image for barcode detection</li>
<li>Access the detected barcode type and image</li>
<li>Retrieve the barcode's <code>x</code> and <code>y</code> coordinates, as well as its <code>height</code> and <code>width</code></li>
<li>Read the barcode's <code>text</code> and <code>value</code></li>
</ol>
</div>
## What Are the Available Output Formats and Their Use Cases?
`BarcodeResult` stores various useful properties. These properties are listed below:
- `BarcodeImage`
- `BarcodeType`
- `BinaryValue`
- Coordinates, `Height` & `Width`
- `PageNumber`
- `Barcode` and `PageOrientation`
- `Text` & `Value`
Each property serves specific purposes in barcode processing workflows. Whether building an inventory management system, document processing pipeline, or quality control application, these data formats provide the flexibility needed for [reading barcodes from various sources](https://ironsoftware.com/csharp/barcode/how-to/read-barcodes-from-images/).
### How Can I Extract and Save Barcode Images?
Once IronBarcode reads an image, the barcodes found in the image are stored in `BarcodeResult` as the `BarcodeImage` property of type `AnyBitmap`. The `BarcodeImage` property stores the found barcode images. Users can retrieve this object to process the image further or save it as a permanent copy. This provides efficiency and ease of use by eliminating additional code to extract barcode images from an image.
Look at the code snippet below that demonstrates a possible use case for this output format:
```csharp
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");
```
The code snippet above illustrates one use case for this output format. Specifically, it creates a multipage TIFF image from barcodes detected within a PDF document. First, we scan or detect barcodes in the sample PDF. Then, we create a list of `AnyBitmap` where we store the information from the `BarcodeImage` property. Finally, we use this list to generate a multi-page TIFF using the `CreateMultiFrameTiff` method. This technique is particularly useful when processing [multipage GIF and TIFF files](https://ironsoftware.com/csharp/barcode/how-to/read-barcodes-from-multi-page-frame-tiff-gif/).
[[i:(`BarcodeImage` property from `BarcodeResult` only stores the images of barcodes found during the read, not the whole input image itself.)]]
### How Do I Identify Different Barcode Types Programmatically?
This property helps determine what type of barcode is present in the input image or document. However, the limitation is that the barcode type inside the image must be supported and readable by IronBarcode. To know more about supported barcode types in IronBarcode, refer to this [article](https://ironsoftware.com/csharp/barcode/how-to/read-barcodes-from-images/#expectbarcodetypes). Additionally, explore the full list of [supported barcode formats](https://ironsoftware.com/csharp/barcode/get-started/supported-barcode-formats/) to ensure compatibility with your specific requirements.
The code snippet below demonstrates how to retrieve barcode values and barcode type in an image by printing the values to console.
```csharp
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);
}
```
From the code snippet above, we perform barcode reading by calling `BarcodeReader.Read()` method on the input image. This returns a `BarcodeResults` object that stores all the `BarcodeResult` from reading all barcodes available in the image. Next, we iterate through the `BarcodeResults` object to retrieve the `BarcodeResult` and get the barcode `value` and `type` printed to the console. This approach works with various barcode types, including specialized formats like [Code 39 barcodes](https://ironsoftware.com/csharp/barcode/how-to/read-code39-barcodes/).
### When Should I Use Binary Value Output?
Using IronBarcode, users can retrieve the byte array of the barcode `value` by accessing the `BinaryValue` property from the `BarcodeResult` object. This allows users to manipulate the barcode `value` further inside the program. Binary `value` output is particularly useful when working with encrypted data, file attachments encoded in barcodes, or when integrating with systems that require byte-level data processing.
The code snippet below demonstrates one use case of retrieving the barcode `value` as binary data:
```csharp
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++;
}
```
Observing the code snippet above, we've created a straightforward program that transforms multiple barcodes within an image into separate new binary-encoded files. Initially, we scan the barcodes in the sample PNG image. Once we've detected these barcodes, we iterate through them, access the `BinaryValue` property, and use it to create new binary files. This technique is especially valuable when you need to [read multiple barcodes](https://ironsoftware.com/csharp/barcode/how-to/read-barcodes-from-images/) and process their binary data individually.
### How Can I Access Barcode Location and Dimensions?
Another property of the `BarcodeResult` object that users can access is the barcode's location via its `Points` property (a `PointF[]` of the barcode's corner coordinates), as well as its `Height` and `Width` within an image file or document. These properties are useful when users need to retrieve information about the barcode's location and dimensions. This spatial information is crucial for applications that require precise positioning, such as automated document processing, quality control systems, or when implementing [crop regions](https://ironsoftware.com/csharp/barcode/how-to/set-crop-region/) for optimized barcode scanning.
Let's demonstrate the barcode's location and dimensions.
```csharp
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);
}
```
<div class="competitors-section__wrapper-even-1">
<div class="competitors__card" style="width: 49%;"><img src="/static-assets/barcode/how-to/output-data-formats/multiple-barcodes.png" alt="Three barcode samples (A, B, C) showing different encoded data with similar visual patterns" class="img-responsive add-shadow" /><p class="competitors__download-link" style="color: #181818; font-style: italic;">Before redaction</p></div>
<div class="competitors__card" style="width: 49%;"><img src="/static-assets/barcode/how-to/output-data-formats/redacted.png" alt="Three redacted content blocks with illegible text fragments" class="img-responsive add-shadow" /><p class="competitors__download-link" style="color: #181818; font-style: italic;">After redaction</p></div>
</div>
The code snippet above redacts multiple barcodes found in an image file. To achieve this, we use a combination of two libraries, IronBarcode and IronDrawing. To get the `BarcodeResult` object and extract the properties from it, we first read the barcodes available in an image file using the `BarcodeReader.Read()` method. Concurrently, the input image file needs to be converted into an `AnyBitmap` object to apply the redaction method to the image. Once we have the `BarcodeResults` object, we can apply a loop and iterate through it to get the `Points`, `Width`, and `Height` of every barcode available in the image (deriving each barcode's top-left `x1`/`y1` corner from `Points`) and use them in the `CropRectangle` properties of the `AnyBitmap.Redact()` method.
### Why Is Page Number Important for Multi-Page Documents?
Users can retrieve the page number at which the barcode was found. This is a helpful feature for users who use a multipage document that contains multiple barcodes and need to know the location of the barcodes found in the document for further processing. This functionality is essential when [reading barcodes from PDF documents](https://ironsoftware.com/csharp/barcode/how-to/read-barcodes-from-pdf/) or processing batch documents in enterprise applications.
Look at the code snippet below:
```csharp
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);
}
```
The code snippet above demonstrates one use case where users need the program to return the `value` of barcodes found in a multipage PDF document and their respective page numbers. The code uses the `BarcodeReader.ReadPdf()` method to read the barcodes inside a multipage PDF document, which returns `BarcodeResults` object storing every `BarcodeResult` found in the document. We apply a loop and iterate through each item in the object to retrieve the `value` of the barcodes and the page number where the barcodes were found. Apart from this use case, users can use this property to debug if all barcodes in a document were read.
[[i:(The value returned from this property is **1-Based**, meaning the first page is always **one** and **not zero**)]]
### How Do I Detect Barcode Rotation and Page Orientation?
Using IronBarcode, users can retrieve information on the barcode orientation and page orientation where the barcode was found. To extract these two pieces of information, access the `Rotation` and `PageOrientation` properties from the `BarcodeResult` object. `Rotation` returns an integer that represents the angle of rotation of the barcode found. This feature works in conjunction with [image orientation correction](https://ironsoftware.com/csharp/barcode/how-to/image-orientation-correction/) capabilities to ensure accurate barcode reading regardless of scan angle.
Look at the code snippet below:
```csharp
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);
}
```
<iframe loading="lazy" src="/static-assets/barcode/how-to/output-data-formats/test.pdf#view=fit" width="100%" height="500px"></iframe>
The code snippet above was run with the sample PDF input attached to prove that users can retrieve the page orientation and barcode rotation by getting the `pageOrientation` and barcode `rotation` respectively. This feature is useful mainly for debugging purposes.
[[i:(IronBarcode can only read barcodes with rotations of `BarcodeResult.PageOrientation`, `BarcodeResult.Rotation`, `0`, `90`, `180`, and `270` degrees. IronBarcode will not return any value if the barcode has a rotation value other than those mentioned. `PageOrientation` returns a [`PageOrientation`](https://ironsoftware.com/csharp/barcode/object-reference/api/IronBarCode.PageOrientation.html) object, which consists of `Portrait` or `Landscape`.)]]
### What's the Difference Between Text and Value Properties?
Of course, the main property that users will want to retrieve when using IronBarcode is its `value` and `text`. These two properties are often used interchangeably and return the same `value`. Apart from that, users can use the `BarcodeResult.ToString()` method to achieve the same result. When working with specialized applications or [exporting barcode data as streams](https://ironsoftware.com/csharp/barcode/how-to/export-barcode-as-stream/), these properties provide flexible ways to access the barcode content in your preferred format.
The code snippet below demonstrates:
```csharp
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());
}
```
From the code snippet above, users only need a few lines of code to read barcodes in an image using IronBarcode. After iterating through the `BarcodeResults` returned by the `BarcodeReader.Read()` method, we output to the console the result of getting the `Value` and `Text` properties, as well as calling the `BarcodeResult.ToString()` method to show that all these return the same `value`.
In a nutshell, IronBarcode is a perfect API for users to perform multiple operations regarding barcodes, not limited to writing and decoding barcodes. With various output data formats supported, users can do much more with the `BarcodeResult` object returned by IronBarcode.
IronBarcode provides multiple output formats from barcode reads including BarcodeImage, BarcodeType, BinaryValue, coordinates, dimensions, page numbers, orientation, text and value properties. These formats enable processing barcode data programmatically for various use cases.
Instead of simply reading the barcode and printing values in the console, IronBarcode offers much more. It provides several output formats that pave the way for users to process read results. These formats include properties such as barcode image, barcode type, BinaryValue, coordinates, height, width, page number, barcode, page orientation, text, and value.
Users can manipulate these properties further within the program. Let's explore how to use these properties and use cases where they can be helpful.
Quickstart: Read Barcode Value and Type in One Line
This example shows how to read a barcode from an image using IronBarcode - one line to load, then immediately print the barcode's value and type. Perfect for getting started fast. For more comprehensive examples, check out the Barcode Quickstart guide.
1Install IronBarcode with NuGet Package Manager
PM > Install-Package BarCode
Install-Package BarCode
2Copy and run this code snippet.
var result = IronBarCode.BarcodeReader.Read("input.png");Console.WriteLine($"Value: {result[0].Value}, Type: {result[0].BarcodeType}");
var result = IronBarCode.BarcodeReader.Read("input.png");
Console.WriteLine($"Value: {result[0].Value}, Type: {result[0].BarcodeType}");
C#
3Deploy to test on your live environment
Start using IronBarcode in your project today with a free trial
Retrieve the barcode's x and y coordinates, as well as its height and width
Read the barcode's text and value
What Are the Available Output Formats and Their Use Cases?
BarcodeResult stores various useful properties. These properties are listed below:
BarcodeImage
BarcodeType
BinaryValue
Coordinates, Height & Width
PageNumber
Barcode and PageOrientation
Text & Value
Each property serves specific purposes in barcode processing workflows. Whether building an inventory management system, document processing pipeline, or quality control application, these data formats provide the flexibility needed for reading barcodes from various sources.
How Can I Extract and Save Barcode Images?
Once IronBarcode reads an image, the barcodes found in the image are stored in BarcodeResult as the BarcodeImage property of type AnyBitmap. The BarcodeImage property stores the found barcode images. Users can retrieve this object to process the image further or save it as a permanent copy. This provides efficiency and ease of use by eliminating additional code to extract barcode images from an image.
Look at the code snippet below that demonstrates a possible use case for this output format:
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")
The code snippet above illustrates one use case for this output format. Specifically, it creates a multipage TIFF image from barcodes detected within a PDF document. First, we scan or detect barcodes in the sample PDF. Then, we create a list of AnyBitmap where we store the information from the BarcodeImage property. Finally, we use this list to generate a multi-page TIFF using the CreateMultiFrameTiff method. This technique is particularly useful when processing multipage GIF and TIFF files.
Please note: BarcodeImage property from BarcodeResult only stores the images of barcodes found during the read, not the whole input image itself.
How Do I Identify Different Barcode Types Programmatically?
This property helps determine what type of barcode is present in the input image or document. However, the limitation is that the barcode type inside the image must be supported and readable by IronBarcode. To know more about supported barcode types in IronBarcode, refer to this article. Additionally, explore the full list of supported barcode formats to ensure compatibility with your specific requirements.
The code snippet below demonstrates how to retrieve barcode values and barcode type in an image by printing the values to console.
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
From the code snippet above, we perform barcode reading by calling BarcodeReader.Read() method on the input image. This returns a BarcodeResults object that stores all the BarcodeResult from reading all barcodes available in the image. Next, we iterate through the BarcodeResults object to retrieve the BarcodeResult and get the barcode value and type printed to the console. This approach works with various barcode types, including specialized formats like Code 39 barcodes.
When Should I Use Binary Value Output?
Using IronBarcode, users can retrieve the byte array of the barcode value by accessing the BinaryValue property from the BarcodeResult object. This allows users to manipulate the barcode value further inside the program. Binary value output is particularly useful when working with encrypted data, file attachments encoded in barcodes, or when integrating with systems that require byte-level data processing.
The code snippet below demonstrates one use case of retrieving the barcode value as binary data:
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
Observing the code snippet above, we've created a straightforward program that transforms multiple barcodes within an image into separate new binary-encoded files. Initially, we scan the barcodes in the sample PNG image. Once we've detected these barcodes, we iterate through them, access the BinaryValue property, and use it to create new binary files. This technique is especially valuable when you need to read multiple barcodes and process their binary data individually.
How Can I Access Barcode Location and Dimensions?
Another property of the BarcodeResult object that users can access is the barcode's location via its Points property (a PointF[] of the barcode's corner coordinates), as well as its Height and Width within an image file or document. These properties are useful when users need to retrieve information about the barcode's location and dimensions. This spatial information is crucial for applications that require precise positioning, such as automated document processing, quality control systems, or when implementing crop regions for optimized barcode scanning.
Let's demonstrate the barcode's location and dimensions.
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
Before redaction
After redaction
The code snippet above redacts multiple barcodes found in an image file. To achieve this, we use a combination of two libraries, IronBarcode and IronDrawing. To get the BarcodeResult object and extract the properties from it, we first read the barcodes available in an image file using the BarcodeReader.Read() method. Concurrently, the input image file needs to be converted into an AnyBitmap object to apply the redaction method to the image. Once we have the BarcodeResults object, we can apply a loop and iterate through it to get the Points, Width, and Height of every barcode available in the image (deriving each barcode's top-left x1/y1 corner from Points) and use them in the CropRectangle properties of the AnyBitmap.Redact() method.
Why Is Page Number Important for Multi-Page Documents?
Users can retrieve the page number at which the barcode was found. This is a helpful feature for users who use a multipage document that contains multiple barcodes and need to know the location of the barcodes found in the document for further processing. This functionality is essential when reading barcodes from PDF documents or processing batch documents in enterprise applications.
Look at the code snippet below:
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
The code snippet above demonstrates one use case where users need the program to return the value of barcodes found in a multipage PDF document and their respective page numbers. The code uses the BarcodeReader.ReadPdf() method to read the barcodes inside a multipage PDF document, which returns BarcodeResults object storing every BarcodeResult found in the document. We apply a loop and iterate through each item in the object to retrieve the value of the barcodes and the page number where the barcodes were found. Apart from this use case, users can use this property to debug if all barcodes in a document were read.
Please note: The value returned from this property is 1-Based, meaning the first page is always one and not zero
How Do I Detect Barcode Rotation and Page Orientation?
Using IronBarcode, users can retrieve information on the barcode orientation and page orientation where the barcode was found. To extract these two pieces of information, access the Rotation and PageOrientation properties from the BarcodeResult object. Rotation returns an integer that represents the angle of rotation of the barcode found. This feature works in conjunction with image orientation correction capabilities to ensure accurate barcode reading regardless of scan angle.
Look at the code snippet below:
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
The code snippet above was run with the sample PDF input attached to prove that users can retrieve the page orientation and barcode rotation by getting the pageOrientation and barcode rotation respectively. This feature is useful mainly for debugging purposes.
Please note: IronBarcode can only read barcodes with rotations of BarcodeResult.PageOrientation, BarcodeResult.Rotation, 0, 90, 180, and 270 degrees. IronBarcode will not return any value if the barcode has a rotation value other than those mentioned. PageOrientation returns a PageOrientation object, which consists of Portrait or Landscape.
What's the Difference Between Text and Value Properties?
Of course, the main property that users will want to retrieve when using IronBarcode is its value and text. These two properties are often used interchangeably and return the same value. Apart from that, users can use the BarcodeResult.ToString() method to achieve the same result. When working with specialized applications or exporting barcode data as streams, these properties provide flexible ways to access the barcode content in your preferred format.
The code snippet below demonstrates:
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
From the code snippet above, users only need a few lines of code to read barcodes in an image using IronBarcode. After iterating through the BarcodeResults returned by the BarcodeReader.Read() method, we output to the console the result of getting the Value and Text properties, as well as calling the BarcodeResult.ToString() method to show that all these return the same value.
In a nutshell, IronBarcode is a perfect API for users to perform multiple operations regarding barcodes, not limited to writing and decoding barcodes. With various output data formats supported, users can do much more with the BarcodeResult object returned by IronBarcode.
Frequently Asked Questions
What are the available barcode output formats in IronBarcode?
IronBarcode provides multiple output formats such as BarcodeImage, BarcodeType, BinaryValue, coordinates, dimensions, page numbers, orientation, text, and value properties. These formats facilitate various data processing needs in .NET applications.
How can I read and immediately print a barcode's value and type?
Using IronBarcode, you can read a barcode from an image and instantly print its value and type with a single line of code. For example: `var result = IronBarCode.BarcodeReader.Read("input.png"); Console.WriteLine($"Value: {result[0].Value}, Type: {result[0].BarcodeType}");`
How can I extract and save barcode images with IronBarcode?
Once a barcode is read, the `BarcodeImage` property can be used to access the image. This image can then be processed or saved as needed using IronBarcode's tools.
What purpose does the BinaryValue output serve in barcode processing?
BinaryValue allows users to retrieve a barcode's byte array, particularly useful for handling encrypted data or integrating with systems requiring byte-level data manipulation.
How can I determine the location and dimensions of a barcode within an image?
IronBarcode provides properties like Points, Height, and Width to determine a barcode's location and dimensions, enabling applications that need precise spatial data.
Why is page number information important when reading multipage documents?
Page number information helps identify where in a multipage document each barcode is located, enabling efficient processing and debugging of documents with numerous barcodes.
How does IronBarcode handle barcode rotation and page orientation?
IronBarcode provides the Rotation and PageOrientation properties to help you identify and correctly process barcodes that may be rotated or on differently oriented pages.
What is the difference between the Text and Value properties in IronBarcode?
The Text and Value properties usually return the same data, representing the content of the barcode. However, they offer flexibility in accessing the barcode's information in the preferred format.
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.