How to Generate a QR Code Using C# with IronBarcode

This tutorial provides a comprehensive guide on generating QR codes using C# with the Iron Barcode library, which is free for development purposes. Follow these steps to efficiently create and customize QR codes for your specific needs.

Step 1: Install the Iron Barcode Package

Ensure you have the Iron Barcode library installed in your project. You can install it via the Package Manager Console with the following command:

Install-Package IronQR

Step 2: Using IronBarcode Namespace

Navigate to your Program.cs file and include the using IronBarCode; namespace at the top of your file:

using IronBarCode;
using IronBarCode;
Imports IronBarCode
$vbLabelText   $csharpLabel

Step 3: Generate a QR Code

To convert your desired text into a QR code, use the QRCodeWriter.CreateQrCode function. This function allows you to generate a QR code that you can then save and manipulate in a variety of ways.

Example Code to Create a QR Code

class Program
{
    static void Main()
    {
        // Define the content for the QR code
        string qrContent = "https://example.com";

        // Create a QR code with default size
        var qrCode = QRCodeWriter.CreateQrCode(qrContent);

        // Save the QR code in different formats
        qrCode.SaveAsPng("QRCode.png");
        qrCode.SaveAsJpeg("QRCode.jpeg");
        qrCode.SaveAsPdf("QRCode.pdf");

        // Output message
        Console.WriteLine("QR codes have been generated and saved in various formats.");
    }
}
class Program
{
    static void Main()
    {
        // Define the content for the QR code
        string qrContent = "https://example.com";

        // Create a QR code with default size
        var qrCode = QRCodeWriter.CreateQrCode(qrContent);

        // Save the QR code in different formats
        qrCode.SaveAsPng("QRCode.png");
        qrCode.SaveAsJpeg("QRCode.jpeg");
        qrCode.SaveAsPdf("QRCode.pdf");

        // Output message
        Console.WriteLine("QR codes have been generated and saved in various formats.");
    }
}
Friend Class Program
	Shared Sub Main()
		' Define the content for the QR code
		Dim qrContent As String = "https://example.com"

		' Create a QR code with default size
		Dim qrCode = QRCodeWriter.CreateQrCode(qrContent)

		' Save the QR code in different formats
		qrCode.SaveAsPng("QRCode.png")
		qrCode.SaveAsJpeg("QRCode.jpeg")
		qrCode.SaveAsPdf("QRCode.pdf")

		' Output message
		Console.WriteLine("QR codes have been generated and saved in various formats.")
	End Sub
End Class
$vbLabelText   $csharpLabel

Step 4: Adjust QR Code Size

To adjust the QR code size, provide your preferred dimensions as a second argument in the CreateQrCode function:

// Create a QR code with custom width and height
var qrCodeCustomSize = QRCodeWriter.CreateQrCode(qrContent, 500);
// Create a QR code with custom width and height
var qrCodeCustomSize = QRCodeWriter.CreateQrCode(qrContent, 500);
' Create a QR code with custom width and height
Dim qrCodeCustomSize = QRCodeWriter.CreateQrCode(qrContent, 500)
$vbLabelText   $csharpLabel

Step 5: Adding Annotations

Enhance your QR code by adding text annotations:

// Add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode();

// Add custom annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Scan the QR code");
// Add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode();

// Add custom annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Scan the QR code");
' Add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode()

' Add custom annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Scan the QR code")
$vbLabelText   $csharpLabel

Step 6: Incorporate Logos into QR Codes

You can customize your QR code by incorporating a logo:

// Path to the logo file
string logoPath = "logo.png";

// Create a QR code with a logo embedded
var qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, logoPath, 200);

// Save the QR code with a logo
qrCodeWithLogo.SaveAsPng("QRCodeWithLogo.png");
// Path to the logo file
string logoPath = "logo.png";

// Create a QR code with a logo embedded
var qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, logoPath, 200);

// Save the QR code with a logo
qrCodeWithLogo.SaveAsPng("QRCodeWithLogo.png");
' Path to the logo file
Dim logoPath As String = "logo.png"

' Create a QR code with a logo embedded
Dim qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, logoPath, 200)

' Save the QR code with a logo
qrCodeWithLogo.SaveAsPng("QRCodeWithLogo.png")
$vbLabelText   $csharpLabel

Conclusion

After following these steps, you can view the generated QR code, complete with annotations and a logo. This step-by-step guide ensures you can efficiently create and customize QR codes according to your specific requirements.

Further Reading: How to Generate a QR Code Using C# with IronBarcode

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.
< PREVIOUS
How to Print a Barcode in ASP .NET
NEXT >
How to Create Barcodes in ASP .NET with IronBarcode

Ready to get started? Version: 2025.6 just released

View Licenses >