Sometimes, the barcode on the image/document might be printed using some angle e.g. at 90 degrees angle as shown in the figure below. In this case, the barcode reader tries to detect the barcode in all possible directions. This may take some longer time to detect the barcode.![]() If you already know the angle or orientation of the barcode in advance, then you can set orientation in BarCodeReader to reduce the recognition time. |
Solution
The barcode in the above image has 90 degree angle and has an orientation of top to bottom. Orientation can be set using BarCodeReader.SetHints() method and passing RecognitionHints.OrientationHints class’ properties.
Aspose.BarCode for .NET supports the following 4 orientation hints:
- NoRotate
- Rotate90
- Rotate180
- Rotate270
The sample code snippet to recognize the barcode in above image using orientation hints is given below:
[C#]
string image = @"code39Extended.jpg";
// create an instance of BarCodeReader and set image and symbology type to recognize
BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard);
// set the orientation
reader.SetHints(RecognitionHints.OrientationHints.Rotate90);
// try to recognize all possible barcodes in the image
while (reader.Read())
{
// display the codetext
Console.WriteLine("Codetext: " + reader.GetCodeText());
}
// close the reader
reader.Close();
[VB.NET]
Dim image As String = "code39Extended.jpg"
' create an instance of BarCodeReader and set image and symbology type to recognize
Dim reader As BarCodeReader = New BarCodeReader(image, BarCodeReadType.Code39Standard)
' set the orientation
reader.SetHints(RecognitionHints.OrientationHints.Rotate90)
' try to recognize all possible barcodes in the image
Do While reader.Read()
' display the codetext
Console.WriteLine("Codetext: " & reader.GetCodeText())
Loop
' close the reader
reader.Close()
The barcode in the above image has 90 degree angle and has an orientation of top to bottom. Orientation can be set using BarCodeReader.SetHints() method and passing RecognitionHints.OrientationHints class’ properties.
Aspose.BarCode for .NET supports the following 4 orientation hints:
- NoRotate
- Rotate90
- Rotate180
- Rotate270
The sample code snippet to recognize the barcode in above image using orientation hints is given below:
[C#]
string image = @"code39Extended.jpg"; // create an instance of BarCodeReader and set image and symbology type to recognize BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard); // set the orientation reader.SetHints(RecognitionHints.OrientationHints.Rotate90); // try to recognize all possible barcodes in the image while (reader.Read()) { // display the codetext Console.WriteLine("Codetext: " + reader.GetCodeText()); } // close the reader reader.Close();
[VB.NET]
Dim image As String = "code39Extended.jpg" ' create an instance of BarCodeReader and set image and symbology type to recognize Dim reader As BarCodeReader = New BarCodeReader(image, BarCodeReadType.Code39Standard) ' set the orientation reader.SetHints(RecognitionHints.OrientationHints.Rotate90) ' try to recognize all possible barcodes in the image Do While reader.Read() ' display the codetext Console.WriteLine("Codetext: " & reader.GetCodeText()) Loop ' close the reader reader.Close()

