Style QR Code

In IronBarcode, the QR codes can have logos added, colors changed, annotation text printed, and margins set.

Below is a sample code snippet demonstrating how to generate a QR code with a logo, custom colors, and annotations using IronBarcode. Ensure you have IronBarcode installed in your project before running this code.

using IronBarCode;   // Import the IronBarcode library

class Program
{
    static void Main()
    {
        // Generate a basic QR code
        var qrCode = QRCodeWriter.CreateQrCode("https://example.com", 500);

        // Customize the QR code to have a different foreground and background color
        qrCode.ChangeBarCodeColor(System.Drawing.Color.BlueViolet, System.Drawing.Color.LightCyan);

        // Add a logo in the center of the QR code
        var logo = System.Drawing.Image.FromFile("path/to/logo.png");
        qrCode.SetLogo(logo);

        // Add annotation text at the bottom of the QR code
        qrCode.AddBarcodeValueTextBelowBarcode();

        // Set the margins around the QR code
        qrCode.SetMargins(10);

        // Save the QR code to a file
        qrCode.SaveAsPng("CustomQRCode.png");

        // Print a success message to the console
        Console.WriteLine("QR Code generated successfully!");
    }
}
using IronBarCode;   // Import the IronBarcode library

class Program
{
    static void Main()
    {
        // Generate a basic QR code
        var qrCode = QRCodeWriter.CreateQrCode("https://example.com", 500);

        // Customize the QR code to have a different foreground and background color
        qrCode.ChangeBarCodeColor(System.Drawing.Color.BlueViolet, System.Drawing.Color.LightCyan);

        // Add a logo in the center of the QR code
        var logo = System.Drawing.Image.FromFile("path/to/logo.png");
        qrCode.SetLogo(logo);

        // Add annotation text at the bottom of the QR code
        qrCode.AddBarcodeValueTextBelowBarcode();

        // Set the margins around the QR code
        qrCode.SetMargins(10);

        // Save the QR code to a file
        qrCode.SaveAsPng("CustomQRCode.png");

        // Print a success message to the console
        Console.WriteLine("QR Code generated successfully!");
    }
}
Imports IronBarCode ' Import the IronBarcode library

Friend Class Program
	Shared Sub Main()
		' Generate a basic QR code
		Dim qrCode = QRCodeWriter.CreateQrCode("https://example.com", 500)

		' Customize the QR code to have a different foreground and background color
		qrCode.ChangeBarCodeColor(System.Drawing.Color.BlueViolet, System.Drawing.Color.LightCyan)

		' Add a logo in the center of the QR code
		Dim logo = System.Drawing.Image.FromFile("path/to/logo.png")
		qrCode.SetLogo(logo)

		' Add annotation text at the bottom of the QR code
		qrCode.AddBarcodeValueTextBelowBarcode()

		' Set the margins around the QR code
		qrCode.SetMargins(10)

		' Save the QR code to a file
		qrCode.SaveAsPng("CustomQRCode.png")

		' Print a success message to the console
		Console.WriteLine("QR Code generated successfully!")
	End Sub
End Class
$vbLabelText   $csharpLabel

Explanation

  1. Importing the IronBarcode Library: This code begins by importing the IronBarcode library, which is necessary to work with QR codes in C#.
  2. Creating the QR Code: The QRCodeWriter.CreateQrCode method generates a QR code for a specified URL ("https://example.com") with a size of 500x500 pixels.
  3. Customizing Colors: The ChangeBarCodeColor method changes the QR code's colors. In this example, the foreground color is set to BlueViolet and the background color to LightCyan.
  4. Adding a Logo: A logo image is added at the center of the QR code using the SetLogo method. Replace "path/to/logo.png" with the actual path to your logo image.
  5. Adding Annotation Text: The method AddBarcodeValueTextBelowBarcode includes text below the QR code that corresponds to the encoded data, aiding in the identification of the QR code content.
  6. Setting Margins: Margins around the QR code can be defined with SetMargins. Here, a margin of 10 pixels is applied on all sides.
  7. Saving the QR Code: Finally, the QR code is saved as a PNG file named "CustomQRCode.png", using the SaveAsPng method.
  8. Output Message: A message is output to the console to indicate successful QR code generation.

Ensure to customize the file paths and parameters as necessary to match your project requirements.