How to Rotate Barcode Image in C#

This step by step tutorial shows you how to rotate barcode image in C#. It rotates the generated barcode at specified angle in C# code. The barcode can be rotated horizontally or vertically as per your needs in your C# applications.

Steps to Rotate Barcode Image in C#

  1. Include Aspose.BarCode for .NET Nuget package
  2. Add reference to Aspose.Barcode and Aspose.BarCode.Generation namespaces
  3. Use SetLicense method to apply the license
  4. Create an object of BarCodeGenerator Class using EncodeType as Code128
  5. Specify the barcode text using CodeText property
  6. Set required rotation angle using RotationAngle attribute
  7. Save the rotated barcode image as PNG image format

In another tutorial, we showed you the code to Generate QR Code in C# from scratch. That barcode had no rotation. However, by following the above steps, you can create rotated barcode in C# as well.

Code to Rotate Barcode Image in C#

using System;
//Use following namespaces to rotate barcode image
using Aspose.BarCode;
using Aspose.BarCode.Generation;
namespace RotateBarCodeImage
{
class Program
{
static void Main(string[] args)
{
//Set license before rotating barcode image
Aspose.BarCode.License AsposeBarCodeLicense = new Aspose.BarCode.License();
AsposeBarCodeLicense.SetLicense(@"c:\asposelicense\license.lic");
//initiate barcode generator object with Code128 encode type
BarcodeGenerator RotateBarCodeImage = new BarcodeGenerator(EncodeTypes.Code128);
RotateBarCodeImage.CodeText = "Product Code 123";
//set rotation of the barcode
RotateBarCodeImage.Parameters.RotationAngle = 45;
//save rotated barcode image as PNG
RotateBarCodeImage.Save("Rotated_BarCode_Image.png", BarCodeImageFormat.Png);
}
}
}

In the above example, we have rotated barcode at 45 degrees, but you can rotate the generated barcode at any degrees. For example, you might want to rotate barcode at 90 degrees in C# web or desktop applications.

 English