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
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.
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
Navigate to your Program.cs
file and include the using IronBarCode;
namespace at the top of your file:
using IronBarCode;
using IronBarCode;
Imports IronBarCode
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.
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
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)
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")
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")
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