Write QR Codes in C#

This article was translated from English: Does it need improvement?
Translated
View the article in English

Introduction

With IronQR, developers can create QR codes for popular image formats and customize them with background colors, margins, logos, and even add them to PDFs. For advanced use, it also offers control over error correction and versions.

This article will explore key features of IronQR with examples, helping you understand how to use it for writing QR codes in C# and apply it effectively in your projects.

Table of Contents

Commencez à utiliser IronQR dans votre projet aujourd'hui avec un essai gratuit.

Première étape :
green arrow pointer

Input Data

Text, URLs, Numbers

IronQR can convert a wide range of data types, including text, URLs, and numbers, into QR codes. Whether you're creating QR code links or text for marketing and communication, numeric codes for inventory management, or encoding binary data or streams into readable QR codes, IronQR provides all the support you need.

Additionally, the API is straightforward. The QrWriter class offers several overloads, enabling different types of data as input, reducing complexity and streamlining the process.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-1.cs
using IronQr;
using IronSoftware.Drawing;

string text = "Hello, World!";
string url = "https://ironsoftware.com/csharp/qr/";
string alphanumeric = "WATERSKU-12356";

// Create QR code
QrCode textQr = QrWriter.Write(text);
// Save QR code as a bitmap
AnyBitmap textQrImage = textQr.Save();
// Save QR code as file
textQrImage.SaveAs("textQr.png");

QrCode urlQr = QrWriter.Write(url);
AnyBitmap urlQrImage = urlQr.Save();
urlQrImage.SaveAs("urlQr.png");

QrCode alphanumericQr = QrWriter.Write(alphanumeric);
AnyBitmap alphanumericQrImage = alphanumericQr.Save();
alphanumericQrImage.SaveAs("alphanumericQr.png");
Imports IronQr
Imports IronSoftware.Drawing

Private text As String = "Hello, World!"
Private url As String = "https://ironsoftware.com/csharp/qr/"
Private alphanumeric As String = "WATERSKU-12356"

' Create QR code
Private textQr As QrCode = QrWriter.Write(text)
' Save QR code as a bitmap
Private textQrImage As AnyBitmap = textQr.Save()
' Save QR code as file
textQrImage.SaveAs("textQr.png")

Dim urlQr As QrCode = QrWriter.Write(url)
Dim urlQrImage As AnyBitmap = urlQr.Save()
urlQrImage.SaveAs("urlQr.png")

Dim alphanumericQr As QrCode = QrWriter.Write(alphanumeric)
Dim alphanumericQrImage As AnyBitmap = alphanumericQr.Save()
alphanumericQrImage.SaveAs("alphanumericQr.png")
$vbLabelText   $csharpLabel

Binary & Streams

Similarly, we can convert binary data and streams into QR codes using the same Write method as mentioned earlier.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-2.cs
using IronQr;
using IronSoftware.Drawing;
using System.Text;

byte[] bytes = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/");

// Create QR code
QrCode bytesQr = QrWriter.Write(bytes);

// Save QR code as a bitmap
AnyBitmap qrImage = bytesQr.Save();

// Save QR code bitmap to file
qrImage.SaveAs("bytesQr.png");
Imports IronQr
Imports IronSoftware.Drawing
Imports System.Text

Private bytes() As Byte = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/qr/")

' Create QR code
Private bytesQr As QrCode = QrWriter.Write(bytes)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = bytesQr.Save()

' Save QR code bitmap to file
qrImage.SaveAs("bytesQr.png")
$vbLabelText   $csharpLabel

class Program { static void Main() { // Create a QR code writer instance QrWriter writer = QrWriter.CreateQrCode();

    // Example binary data
    byte[] data = { 0x01, 0x02, 0x03, 0x04 };

    // Write binary data to QR code
    writer.Write(data)
          .SaveAs("binary-qr.png");

    // Example using a memory stream
    using (MemoryStream stream = new MemoryStream(data))
    {
        writer.Write(stream)
              .SaveAs("stream-qr.png");
    }
}

}


The `Write` method has overloads that accept both byte arrays and streams as inputs. For streams, we can create a `MemoryStream` from the byte array and then convert it into a QR code. This is useful when users require more fine-grained control over data chunks, as streams can be more memory-efficient.

```cs
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-3.cs

Export QR Codes

IronQR is flexible and adaptable to various use cases that require different file formats. You can save QR codes in multiple formats such as JPG, PNG, GIF, and TIFF using the SaveAs method.

Save as Image

The SaveAs method from AnyBitmap automatically detects the file format based on the provided file path. In this example, I specified a file path ending with .png.

Veuillez noterWhen using the SaveAs method, please note that there is no default image format. If you enter an unrecognized extension or make a typo in the file path, the image will be saved with the incorrect extension.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-4.cs
using IronQr;
using IronSoftware.Drawing;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qr.png");
Imports IronQr
Imports IronSoftware.Drawing

' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()

' Save QR code bitmap as file
qrImage.SaveAs("qr.png")
$vbLabelText   $csharpLabel

System.Drawing.Images

Converting images to the System.Drawing.Images object from Microsoft allows you to use the Bitmap class to save the QR code to a file path. In this example, the Save method saves the QR code as a PNG file to the path qrBitmap.png.

Veuillez noterSystem.Drawing.Common is only supported on the Windows platform.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-5.cs
using IronQr;
using System.Drawing;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

// Save QR code as a bitmap
Bitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.Save("qrBitmap.png");
Imports IronQr
Imports System.Drawing

' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")

' Save QR code as a bitmap
Private qrImage As Bitmap = qr.Save()

' Save QR code bitmap as file
qrImage.Save("qrBitmap.png")
$vbLabelText   $csharpLabel

IronSoftware.Drawing

Due to the lack of cross-platform compatibility of System.Drawing.Common, developers may encounter issues when maintaining cross-platform applications. IronQR can utilize both System.Drawing.Common and IronSoftware.Drawing.

IronQR uses the AnyBitmap class from IronSoftware.Drawing, a universally compatible Bitmap class that implicitly casts to the following:

  • System.Drawing.Bitmap
  • System.Drawing.Image
  • SkiaSharp.SKBitmap
  • SixLabors.ImageSharp
  • Microsoft.Maui.Graphics.Platform.PlatformImage

With this powerful open-source library, IronQR achieves cross-platform support and compatibility with .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard, and .NET Framework 4.6.2+. To learn more about the library, please refer to IronSoftware.Drawing website.

Stamp on PDF

IronQR allows developers to stamp QR codes onto existing PDF documents, making it easy for others to quickly access links or additional resources. Stamping QR codes on both single and multiple pages is supported.

Stamp to a Single Page

After creating the QR code, call the StampToExistingPdfPage method from the QrCode object. This method requires the file path, coordinates (x and y), page number, and an optional password if the PDF is password-protected. Once the arguments are provided, the method stamps the QR code and saves the PDF.

Veuillez noterThis method is based on the PDF pages, with page numbering starting at 1 instead of 0.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-6.cs
using IronQr;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

string filepath = "example.pdf";
int x = 100;
int y = 150;
int page = 1;

// Stamp QR code to (100, 150) of the pdf on page 1
qr.StampToExistingPdfPage(filepath, x, y, page);
Imports IronQr

' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")

Private filepath As String = "example.pdf"
Private x As Integer = 100
Private y As Integer = 150
Private page As Integer = 1

' Stamp QR code to (100, 150) of the pdf on page 1
qr.StampToExistingPdfPage(filepath, x, y, page)
$vbLabelText   $csharpLabel

Stamp to Multiple Pages

Similar to the example above, the main difference is that the StampToExistingPdfPages method takes a list of page numbers instead of just one.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-7.cs
using IronQr;
using System.Collections.Generic;

// Create a QR code object
QrCode qr = QrWriter.Write("hello world");

string filepath = "example.pdf";
int x = 100;
int y = 150;
List<int> pages = new List<int>();
pages.Add(1);
pages.Add(2);
pages.Add(3);
pages.Add(4);

// Stamp QR code to (100, 150) of the pdf on pages 1-4
qr.StampToExistingPdfPages(filepath, x, y, pages);
Imports IronQr
Imports System.Collections.Generic

' Create a QR code object
Private qr As QrCode = QrWriter.Write("hello world")

Private filepath As String = "example.pdf"
Private x As Integer = 100
Private y As Integer = 150
Private pages As New List(Of Integer)()
pages.Add(1)
pages.Add(2)
pages.Add(3)
pages.Add(4)

' Stamp QR code to (100, 150) of the pdf on pages 1-4
qr.StampToExistingPdfPages(filepath, x, y, pages)
$vbLabelText   $csharpLabel

Output from Both Examples

alt text


QR Code Options

IronQR offers extensive customization options for fine-tuning QR code behavior and functionality. The QrOptions class provides several parameters, such as version control, encoding type, character encoding, and error correction levels. Let’s explore these options in more detail.

Encoding

IronQR supports multiple types of QR codes for both creation and reading. Below are the supported types:

  • QRCode: This is the standard QR code, commonly used today. It can store up to 7,089 numeric characters or 4,296 alphanumeric characters.
  • MicroQRCode: A smaller version of the standard QR code, it can store up to 35 numeric characters or 21 alphanumeric characters.
  • RMQRCode: The Rectangular Micro QR Code is a compact version of the QR code, offering flexibility in its aspect ratio.
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-8.cs
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change encoding to micro QR code
    Encoding = IronQr.Enum.QrEncoding.MicroQRCode,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing

Private options As New QrOptions With {.Encoding = IronQr.Enum.QrEncoding.MicroQRCode}

' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()

' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
$vbLabelText   $csharpLabel

Error Correction

IronQR uses standard QR error correction to ensure that all QR codes produced are fault-tolerant and reliable, even in harsh conditions. Additionally, IronQR allows you total control over error correction level for further fine-tuning.

There are four levels of error correction available, provided by QrErrorCorrectionLevel:

  • Highest: 30% error correction
  • High: 25% error correction
  • Medium: 15% error correction
  • Low: 7% error correction
:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-9.cs
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change error correction level to medium
    ErrorCorrectionLevel = QrErrorCorrectionLevel.Medium,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing

Private options As New QrOptions With {.ErrorCorrectionLevel = QrErrorCorrectionLevel.Medium}

' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()

' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
$vbLabelText   $csharpLabel

Higher error correction provides greater fault tolerance when reading the QR code, making it more likely to be scanned at lower resolutions compared to one with low error correction. You may test out based on your use cases.

alt text

QR Code Version

You can adjust the QR code version to store more data. Higher versions are ideal for inventory or logistics, while lower versions work well for smaller data, like short URLs. Simply change the Version property in the QrOptions object and pass it to the Write method to generate the QR code as needed.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-10.cs
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change QR code version to 40
    Version = 40,
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing

Private options As New QrOptions With {.Version = 40}

' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()

' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
$vbLabelText   $csharpLabel

alt text

As you can see from the output, version 40 of the QR code is highly complex and dense compared to version 5.

Lower versions require more precise scanning and may be difficult to scan without higher-resolution scanners. However, higher versions are easier to scan, even with lower-resolution cameras. For a more detailed guide on choosing the QR version based on capacity, please refer to the QR version list.

Character Encoding

This option determines how the QR code is encoded. In our example, we changed it to 'UTF-32', while the default character encoding is 'ISO-8859-1.'

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-11.cs
using IronQr;
using IronSoftware.Drawing;

QrOptions options = new QrOptions
{
    // Change character encoding to UTF-32
    CharacterEncoding = "UTF-32"
};

// Create QR code
QrCode qr = QrWriter.Write("1234", options);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save();

// Save QR code bitmap as file
qrImage.SaveAs("qrImage.png");
Imports IronQr
Imports IronSoftware.Drawing

Private options As New QrOptions With {.CharacterEncoding = "UTF-32"}

' Create QR code
Private qr As QrCode = QrWriter.Write("1234", options)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save()

' Save QR code bitmap as file
qrImage.SaveAs("qrImage.png")
$vbLabelText   $csharpLabel

QR Code Styling

In addition to its easy-to-use methods and flexibility in handling input data, IronQR offers many options for customizing and styling QR codes to make them unique. The QrStyleOptions class provides various parameters for customizing all aspects of a QR code. Let’s explore the available options.

Resize

To resize the QR code, you can set the Dimensions property of the QrStyleOptions object and then pass it to the Save method. By default, the QR code is saved at 300px. In this example, we saved the QR code at 600px instead of 300px.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-12.cs
using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change the dimensions to 600px
    Dimensions = 600,
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLResized.png");
Imports IronQr
Imports IronSoftware.Drawing

Private styleOptions As New QrStyleOptions() With {.Dimensions = 600}

Private url As String = "https://ironsoftware.com/csharp/qr/"

' Create QR code
Private qr As QrCode = QrWriter.Write(url)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)

' Save QR code bitmap as file
qrImage.SaveAs("qrURLResized.png")
$vbLabelText   $csharpLabel

alt text

Margins & Borders

To adjust the margins and borders, we can use the Margins property of the QrStyleOptions class. This property controls the margins of the QR code on all sides, with a default value of 10px. In our example, we set the margin to 20px.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-13.cs
using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change margins to 20px
    Margins = 20
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");
Imports IronQr
Imports IronSoftware.Drawing

Private styleOptions As New QrStyleOptions() With {.Margins = 20}

Private url As String = "https://ironsoftware.com/csharp/qr/"

' Create QR code
Private qr As QrCode = QrWriter.Write(url)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)

' Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png")
$vbLabelText   $csharpLabel

alt text

Change Margins for Each Side

IronQR also allows users to specify different margins for each side, providing more fine-grained control.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-14.cs
using IronQr;
using IronSoftware.Drawing;

QrStyleOptions styleOptions = new QrStyleOptions()
{
    // Change margins
    MarginBottom = 30,
    MarginTop = 100,
    MarginRight = 40,
    MarginLeft = 20,
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png");
Imports IronQr
Imports IronSoftware.Drawing

Private styleOptions As New QrStyleOptions() With {
	.MarginBottom = 30,
	.MarginTop = 100,
	.MarginRight = 40,
	.MarginLeft = 20
}

Private url As String = "https://ironsoftware.com/csharp/qr/"

' Create QR code
Private qr As QrCode = QrWriter.Write(url)

' Save QR code as a bitmap
Private qrImage As AnyBitmap = qr.Save(styleOptions)

' Save QR code bitmap as file
qrImage.SaveAs("qrURLMarginMultiple.png")
$vbLabelText   $csharpLabel

Recolor

We can add colors to the QR code and its background using the QrStyleOptions class. Customizing colors makes the QR code more unique and eye-catching. You can change the color using the Color and BackgroundColor properties. Be sure to import IronSoftware.Drawing for a list of available colors to assign.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-15.cs
using IronQr;
using IronSoftware.Drawing;

// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");

// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
    Logo = new QrLogo(logo, 50, 50, 10),
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

alt text

In addition to colors and dimensions, you can also apply your company logo to the QR code. This helps users immediately recognize and associate the QR code with your brand. The Logo property makes it easy to customize a QR code by adding your company’s logo.

:path=/static-assets/qr/content-code-examples/tutorials/csharp-qr-writing-15.cs
using IronQr;
using IronSoftware.Drawing;

// Load new logo image
AnyBitmap logo = AnyBitmap.FromFile("sample.png");

// Add new logo to QR code style options
QrStyleOptions styleOptions = new QrStyleOptions()
{
    Logo = new QrLogo(logo, 50, 50, 10),
};

string url = "https://ironsoftware.com/csharp/qr/";

// Create QR code
QrCode qr = QrWriter.Write(url);

// Save QR code as a bitmap
AnyBitmap qrImage = qr.Save(styleOptions);

// Save QR code bitmap as file
qrImage.SaveAs("qrURLColored.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

alt text

The QrLogo class allows further customization of the logo's appearance. Below are the available properties:

  • Bitmap: Represents the image you want to use as the logo.
  • Width: Represents the logo’s width. The default value is 0.
  • Height: Represents the logo’s height. The default value is 0.
  • CornerRadius: Represents the radius for rounding the logo’s corners. By default, it's set to 0, meaning the logo will have square corners.
using IronQRCode;
using IronSoftware.Drawing;

class Program
{
    static void Main()
    {
        QrStyleOptions styleOptions = new QrStyleOptions
        {
            Logo = new QrLogo
            {
                Bitmap = AnyBitmap.FromBitmap("path/to/logo.png"),
                Width = 50,
                Height = 50,
                CornerRadius = 5
            }
        };

        QrCode qr = QrWriter.CreateQrCode()
                               .Write("Customized Logo Example");

        qr.SaveAs("example-customized-logo-qr.png", styleOptions);
    }
}
using IronQRCode;
using IronSoftware.Drawing;

class Program
{
    static void Main()
    {
        QrStyleOptions styleOptions = new QrStyleOptions
        {
            Logo = new QrLogo
            {
                Bitmap = AnyBitmap.FromBitmap("path/to/logo.png"),
                Width = 50,
                Height = 50,
                CornerRadius = 5
            }
        };

        QrCode qr = QrWriter.CreateQrCode()
                               .Write("Customized Logo Example");

        qr.SaveAs("example-customized-logo-qr.png", styleOptions);
    }
}
Imports IronQRCode
Imports IronSoftware.Drawing

Friend Class Program
	Shared Sub Main()
		Dim styleOptions As New QrStyleOptions With {
			.Logo = New QrLogo With {
				.Bitmap = AnyBitmap.FromBitmap("path/to/logo.png"),
				.Width = 50,
				.Height = 50,
				.CornerRadius = 5
			}
		}

		Dim qr As QrCode = QrWriter.CreateQrCode().Write("Customized Logo Example")

		qr.SaveAs("example-customized-logo-qr.png", styleOptions)
	End Sub
End Class
$vbLabelText   $csharpLabel

Checking Fault Tolerance

Along with extensive flexibility in file formats and customizations, the flexibility extends to debugging and error-handling aspects. IronQR provides various tools for developers to handle exceptions and write unit tests to verify applications.

CheckSums

QR codes may sometimes become damaged, but IronQR includes built-in checksums and data correction to keep them functional. It uses the Reed-Solomon error correction algorithm, ensuring that QR codes remain fault-tolerant.

Detailed Error Messages

IronQR provides detailed error messages that help users quickly identify issues. These messages contain a list of specific exceptions, making debugging and problem-solving more straightforward. Below is a list of IronQrException used by the library.

  • IronQrEncodingException: A subclass of IronQrException, this error occurs when there is an issue with writing the QR code. For instance, it will appear if a user attempts to create a QR code from an empty string.

alt text

  • IronQrFileException: A subclass of IronQrException, this error occurs when a file-related issue arises.

  • IronQrPdfPasswordExcception: A subclass of IronQrException, this error occurs when the PDF a user is trying to stamp is password-protected, and either no password or an incorrect password is provided. It also covers other PDF-related errors, such as when the PDF cannot be opened, as shown in the example.

alt text

Conclusion

IronQR provides a comprehensive set of methods for generating and customizing QR codes within .NET applications. With its robust features, developers can easily create QR codes with various data encodings, visual styles, and error correction levels. The library's support for diverse output formats and seamless integration into existing documents makes it a versatile tool for any QR code project. Whether you need basic QR codes or advanced, branded solutions, IronQR offers the flexibility and functionality to meet your needs efficiently.

To learn more, check out the IronQR documentation, start exploring with a free trial, and review the licensing options to see which plan best suits your needs.

Questions Fréquemment Posées

Comment générer un code QR en C# ?

Vous pouvez générer un code QR en C# en utilisant la classe QrWriter disponible dans IronQR. Cette classe vous permet d'écrire des données dans un code QR et de le sauvegarder dans divers formats d'image. Utilisez simplement la méthode Write pour encoder vos données et SaveAs pour produire le code QR.

Quels types de personnalisation puis-je appliquer aux codes QR?

IronQR vous permet de personnaliser les codes QR en modifiant leurs couleurs, en ajoutant des logos, en redimensionnant et en ajustant les marges. Utilisez la classe QrStyleOptions pour appliquer ces personnalisations.

Puis-je intégrer un code QR dans un PDF en utilisant C#?

Oui, vous pouvez intégrer un code QR dans un PDF en utilisant IronQR grâce aux méthodes StampToExistingPdfPage ou StampToExistingPdfPages. Cela vous permet de spécifier l'emplacement et les pages où le code QR doit apparaître.

Comment puis-je gérer les erreurs lors de la création des codes QR?

IronQR dispose de fonctionnalités de gestion des erreurs robustes, fournissant des messages d'erreur tels que IronQrEncodingException, IronQrFileException, et IronQrPdfPasswordException pour aider au débogage et à la résolution des problèmes.

Quels formats puis-je exporter des codes QR?

En utilisant IronQR, vous pouvez exporter des codes QR vers divers formats, y compris JPG, PNG, GIF, et TIFF. La méthode SaveAs vous permet de spécifier le format désiré pour votre sortie de code QR.

Cette bibliothèque supporte-t-elle le développement multiplateforme?

Oui, IronQR prend en charge le développement multiplateforme via la bibliothèque Iron Software.Drawing, le rendant compatible avec différentes versions et plateformes .NET.

Est-il possible d'ajouter un logo à un code QR pour le branding?

Vous pouvez ajouter un logo à un code QR en utilisant IronQR en configurant la propriété Logo dans la classe QrStyleOptions, permettant des codes QR de marque avec des apparences de logo personnalisées.

Quel est le but de la correction d'erreur dans les codes QR?

La correction d'erreur dans les codes QR, prise en charge par IronQR, garantit que les codes QR restent lisibles même s'ils sont partiellement endommagés. Cette fonctionnalité offre quatre niveaux de correction : Élevé, Haut, Moyen et Bas, pour s'adapter à différents cas d'utilisation.

Quels types de données peuvent être encodés dans des codes QR?

IronQR peut encoder une variété de types de données dans les codes QR, y compris du texte, des URL, des numéros, des données binaires, et des flux, offrant une flexibilité dans les données que vous pouvez représenter.

Comment puis-je créer un code QR avec une URL en C#?

Pour créer un code QR avec une URL en C#, utilisez la classe QrWriter dans IronQR. Utilisez la méthode Write pour encoder l'URL et SaveAs pour stocker le code QR sous forme d'image.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 47,669 | Version : 2025.11 vient de sortir