How to Fix Barcode Orientation
Barcode orientation refers to the angle at which a barcode is printed or displayed on a product or document. It can be adjusted to various angles to fit different layout and design requirements. The most common orientation is horizontal, where the barcode is aligned from left to right, which is the standard and most widely used format. Any non-zero orientation degree poses a challenge for libraries to detect and retrieve the value. IronBarcode offers automatic orientation correction to detect any non-zero orientations for barcodes and QR codes.
How to Fix Barcode Orientation
- Download the C# library to fix barcode orientation
- Set the AutoRotate property to true
- Import the targeted barcodes and QR codes
- Read the barcodes and QR codes with the reading option
- Retrieve the resulitng barcode value
Install with NuGet
Install-Package BarCode
Download DLL
Manually install into your project
Install with NuGet
Install-Package BarCode
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronBarcode on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming with C#.
Install-Package BarCode
Consider installing the IronBarcode DLL directly. Download and manually install it for your project or GAC form: IronBarCode.zip
Manually install into your project
Download DLLFix Barcode Orientation Example
To apply automatic orientation correction, set the AutoRotate property in BarcodeReaderOptions to true. This property is set to true by default, so you should not have to do anything. Reading any non-zero oriented barcode image should work out of the box.
Let's use the image below as our sample. Download the following 20° rotation and 45° rotation sample images.
20° Rotation
45° Rotation
Code
:path=/static-assets/barcode/content-code-examples/how-to/image-orientation-correct-autorotate.cs
using IronBarCode;
using System;
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Turn on auto rotation in ML detection
AutoRotate = true,
};
var results = BarcodeReader.Read("rotate20.png", myOptionsExample);
// Print out the value
Console.WriteLine(results[0].Value);
Imports IronBarCode
Imports System
Private myOptionsExample As New BarcodeReaderOptions() With {.AutoRotate = True}
Private results = BarcodeReader.Read("rotate20.png", myOptionsExample)
' Print out the value
Console.WriteLine(results(0).Value)
In many cases, correcting rotation may not be sufficient, and a filter is required. Learn how to use image filters in the following article: "How to use Image Correction Filters."