Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, you'll learn how to generate QR codes using C# with the Iron Barcode library, which is free for development. Begin by accessing the package manager console and installing the Iron Barcode library using the command:
Install-Package BarCode
Once installed, navigate to the Program.cs
file and include the using IronBarcode
namespace.
To create a QR code, use the QRCodeWriter.CreateQrCode
function, providing the desired text as an argument, such as 'ironsoftware.com'. Save the QR code in formats like JPEG, PNG, or others by specifying the path and filename. If needed, adjust the QR code's size by passing the required dimensions as a second argument. Additionally, Iron Barcode allows you to add text below or above the QR code using AddBarcodeValueTextBelowBarcode
and AddAnnotationTextAboveBarcode
functions. To enhance the QR code with a logo, replace the create QR code function with CreateQrCodeWithLogo
, passing the QR code value, logo file path, and size as arguments. Execute the program, and you'll find the generated QR code image in the output folder, complete with any added annotations, text, and logo. This tutorial provides a comprehensive approach to customizing QR codes, and for further assistance, a support team is available.
Here is a sample C# code for generating a customized QR code:
using System;
using IronBarCode;
namespace QrCodeGenerator
{
class Program
{
static void Main(string[] args)
{
// The value to encode within the QR code
string qrContent = "ironsoftware.com";
// Generate a basic QR code
var qrCode = QRCodeWriter.CreateQrCode(qrContent, 500); // 500 is the DPI for the generated QR code image
// Optionally, add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode();
// Optionally, add annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Visit Our Site");
// Save the generated QR code as a PNG file
qrCode.SaveAsPng("qrcode.png");
Console.WriteLine("QR Code generated and saved as 'qrcode.png'");
// If you want to add a logo to the QR code
string logoPath = "logo.png"; // Path to your logo file
var qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, 500, logoPath, 50); // 50 is the size percentage of the logo
qrCodeWithLogo.SaveAsPng("qrcode_with_logo.png");
Console.WriteLine("QR Code with logo generated and saved as 'qrcode_with_logo.png'");
}
}
}
using System;
using IronBarCode;
namespace QrCodeGenerator
{
class Program
{
static void Main(string[] args)
{
// The value to encode within the QR code
string qrContent = "ironsoftware.com";
// Generate a basic QR code
var qrCode = QRCodeWriter.CreateQrCode(qrContent, 500); // 500 is the DPI for the generated QR code image
// Optionally, add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode();
// Optionally, add annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Visit Our Site");
// Save the generated QR code as a PNG file
qrCode.SaveAsPng("qrcode.png");
Console.WriteLine("QR Code generated and saved as 'qrcode.png'");
// If you want to add a logo to the QR code
string logoPath = "logo.png"; // Path to your logo file
var qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, 500, logoPath, 50); // 50 is the size percentage of the logo
qrCodeWithLogo.SaveAsPng("qrcode_with_logo.png");
Console.WriteLine("QR Code with logo generated and saved as 'qrcode_with_logo.png'");
}
}
}
Imports System
Imports IronBarCode
Namespace QrCodeGenerator
Friend Class Program
Shared Sub Main(ByVal args() As String)
' The value to encode within the QR code
Dim qrContent As String = "ironsoftware.com"
' Generate a basic QR code
Dim qrCode = QRCodeWriter.CreateQrCode(qrContent, 500) ' 500 is the DPI for the generated QR code image
' Optionally, add text below the QR code
qrCode.AddBarcodeValueTextBelowBarcode()
' Optionally, add annotation text above the QR code
qrCode.AddAnnotationTextAboveBarcode("Visit Our Site")
' Save the generated QR code as a PNG file
qrCode.SaveAsPng("qrcode.png")
Console.WriteLine("QR Code generated and saved as 'qrcode.png'")
' If you want to add a logo to the QR code
Dim logoPath As String = "logo.png" ' Path to your logo file
Dim qrCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo(qrContent, 500, logoPath, 50) ' 50 is the size percentage of the logo
qrCodeWithLogo.SaveAsPng("qrcode_with_logo.png")
Console.WriteLine("QR Code with logo generated and saved as 'qrcode_with_logo.png'")
End Sub
End Class
End Namespace
Further Reading: How to Generate a QR Code Using C# with IronBarcode