USING IRONQR

How to Generate QR code using QRCoder compare to IronQR in .NET 6

Published April 29, 2024
Share:

QR Code Generation in C#

Creating QR codes in C# applications is a common requirement for developers, especially for applications involving product identification, ticketing, or sharing URLs and other data easily. There are several libraries available for generating QR codes in C#. Two notable options are QRCoder and IronQR. Here, we'll explore both, comparing their capabilities, ease of use, performance, and other factors relevant for developers working with .NET 6. In this article, we'll delve into a detailed comparison of these libraries, examining their features, ease of use, license, and more, along with code samples to illustrate their usage.

How to Generate QR code using QRCoder compare to IronQR in .NET 6

  1. Create a new Visual Studio project to Generate a QR code
  2. Install QRCoder and IronQR NuGet packages to compare
  3. Create QR codes using QRCoder and IronQR
  4. Customization Options with QRCoder and IronQR

QRCoder

QRCoder is an open-source library written in C# and QR Code implementation that allows you to generate QR Codes as defined by ISO/IEC 18004 in any .NET application. It’s a lightweight and easy-to-use library with no dependencies on other libraries or network stacks.

Here are the key features and benefits of QRCoder:

1. Ease of Use

C# QRCoder offers a straightforward and intuitive API, making it easy for developers to generate QR codes/ QR code text with minimal effort. Its simplicity allows developers of all skill levels to quickly integrate QR code generation into their projects.

2. Extensive Customization Options

One of the standout features of QRCoder is its ability to customize QR codes according to specific requirements. Developers can adjust parameters such as error correction level, size, color, and even embed logos or images within the QR code.

3. Multiple Encoding Formats

QRCoder supports various encoding formats, enabling developers to encode different types of data into QR codes. Whether it's plain text, URLs, contact information, or Wi-Fi credentials, QRCoder can handle a wide range of data formats.

4. High-Quality Output

The QR codes generated by C# QRCoder are of high quality, ensuring readability and reliability across different devices and scanning conditions. This reliability is crucial for applications where QR codes serve as a bridge between physical and digital interactions.

5. Open-Source and Active Development

C# QRCoder is an open-source project, allowing developers to contribute to its development and ensuring continuous improvements and updates. This active community engagement fosters innovation and ensures that the library remains relevant in the ever-evolving landscape of technology.

IronQR

IronQR is a powerful C# QR Code library developed and maintained by Iron Software. It allows C# software engineers to detect, read, and create QR Codes in .NET applications and websites. Here are some key features of IronQR:

QR Code Generation

IronQR enables highly customizable QR code generation. You can create QR codes with various options, such as resizing, margins, borders, and recoloring.

using IronQr;
using IronSoftware.Drawing;
// Prepare a QR Code object
QrCode theQrGen = QrWriter.Write("Awesome IronQR");
// Save QR Code to memory
AnyBitmap myQrImage = theQrGen.Save();
// Save QR Code image to disk
myQrImage.SaveAs("awesome.png");
using IronQr;
using IronSoftware.Drawing;
// Prepare a QR Code object
QrCode theQrGen = QrWriter.Write("Awesome IronQR");
// Save QR Code to memory
AnyBitmap myQrImage = theQrGen.Save();
// Save QR Code image to disk
myQrImage.SaveAs("awesome.png");
Imports IronQr
Imports IronSoftware.Drawing
' Prepare a QR Code object
Private theQrGen As QrCode = QrWriter.Write("Awesome IronQR")
' Save QR Code to memory
Private myQrImage As AnyBitmap = theQrGen.Save()
' Save QR Code image to disk
myQrImage.SaveAs("awesome.png")
VB   C#

QR Code Reading

IronQR uses an advanced Machine Learning Model for QR code detection. This model ensures accurate and fast QR code reading. IronQR supports reading QR codes from various image formats, including JPG, PNG, SVG, bmp, and multipage images like gif and tiff.

using IronQr;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Read QR code
var inputBmp = AnyBitmap.FromFile("awesome.png");
// Load the image into QrImageInput
QrImageInput imageInput = new QrImageInput(inputBmp);
// Create the QR Reader object
QrReader reader = new QrReader();
// Read the Input an get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);
using IronQr;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Read QR code
var inputBmp = AnyBitmap.FromFile("awesome.png");
// Load the image into QrImageInput
QrImageInput imageInput = new QrImageInput(inputBmp);
// Create the QR Reader object
QrReader reader = new QrReader();
// Read the Input an get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);
Imports IronQr
Imports IronSoftware.Drawing
Imports System.Collections.Generic
' Read QR code
Private inputBmp = AnyBitmap.FromFile("awesome.png")
' Load the image into QrImageInput
Private imageInput As New QrImageInput(inputBmp)
' Create the QR Reader object
Private reader As New QrReader()
' Read the Input an get all embedded QR Codes
Private results As IEnumerable(Of QrResult) = reader.Read(imageInput)
VB   C#

Cross-Platform Compatibility

  1. Desktop: Works with Windows desktop applications (WPF & MAUI).
  2. Mobile: Compatible with Xamarin and MAUI.
  3. Web: Supports Blazor and WebForms.
  4. Console: App and library environments.
  5. Cloud: Docker, Azure, and AWS.

Encoding Data

You can encode various types of data in QR codes, including text, URLs, bytes, and numbers.

Error Correction

IronQR provides detailed error messages and custom error correction options.

Trusted by Millions, IronQR is trusted by engineers worldwide for its reliability and ease of use. To get started with IronQR, you can install it via NuGet.

Step1: Create a new Visual Studio project to Generate a QR code

To get started with the code, let us create a Visual Studio Project. Open Microsoft Visual Studio 2022 and select "Create a new project" option.

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 1 - Open Visual Studio and click on "Create a new project" option

Select the Console application template from the template list

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 2 - Select the project type as "Console App".

Then provide the project name and the solution names. Select the path to store the project files

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 3 - Configure your project by specifying the project name, location and solution name, then click on Next.

Select the required .NET version. I will go with the latest .NET 8 framework at the time of writing this article.

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 4 - Select the latest .NET Framework version and click on the Create button.

Once you click the create button the project is created and ready for development.

Step 2: Install QRCoder and IronQR NuGet packages

The QRCoder NuGet package can be installed using Visual Studio NuGet package manager as shown below.

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 5 - Install QRCoder using the Manage NuGet Package for Solution by searching "QRCoder" in the search bar of NuGet Package Manager, then select the project and click on the Install button.

Or install it from NuGet package manager console using the following command

dotnet add package QRCoder --version 1.4.3
dotnet add package QRCoder --version 1.4.3
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet add package QRCoder --version 1.4.3
VB   C#

The QRCoder NuGet package is available on the NuGet website here

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 6 - QRCoder NuGet package

The IronQR can also be installed similarly using the Visual Studio NuGet package manager, shown below.

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 7 - Install IronQR using the Manage NuGet Package for Solution by searching "IronQR" in the search bar of NuGet Package Manager, then select the project and click on the Install button.

Also from the NuGet package manager console, use the following command

dotnet add package IronQR --version 2024.4.1
dotnet add package IronQR --version 2024.4.1
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet add package IronQR --version 2024.4.1
VB   C#

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 8 - IronQR NuGet Package

Step 3: Create QR codes using QRCoder and IronQR

Creating QR codes in the two libraries requires simple code, let's check them out

QRCoder

The following code shows how to generate our first QR code using QRCoder

using QRCoder;
using System.Drawing;
namespace QRCoderVsIronQR
{
public class Program
{
    public static void Main()
    {
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
            using (var qrCode = new QRCoder.BitmapByteQRCode(qrCodeData))
            {
                var qrCodeImage = qrCode.GetGraphic(20);
                var file = Image.FromStream(new MemoryStream(qrCodeImage));
                file.Save("QrCoderDemo1.png");
            }
        }
    }
}
using QRCoder;
using System.Drawing;
namespace QRCoderVsIronQR
{
public class Program
{
    public static void Main()
    {
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
            using (var qrCode = new QRCoder.BitmapByteQRCode(qrCodeData))
            {
                var qrCodeImage = qrCode.GetGraphic(20);
                var file = Image.FromStream(new MemoryStream(qrCodeImage));
                file.Save("QrCoderDemo1.png");
            }
        }
    }
}
Imports QRCoder
Imports System.Drawing
Namespace QRCoderVsIronQR
Public Class Program
	Public Shared Sub Main()
			Using qrGenerator As New QRCodeGenerator()
			Using qrCodeData As QRCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q)
			Using qrCode = New QRCoder.BitmapByteQRCode(qrCodeData)
				Dim qrCodeImage = qrCode.GetGraphic(20)
				Dim file = Image.FromStream(New MemoryStream(qrCodeImage))
				file.Save("QrCoderDemo1.png")
			End Using
			End Using
			End Using
	End Sub
End Class
End Namespace
VB   C#

Code Explanation

  1. We create QRCodeGenerator and call the CreateQrCode method to generate QR code graphic
  2. Then we use the QRCoder.BitmapByteQRCode method to get the byte array from the GetGraphic method
  3. Then we save the byte stream as image using Image.FromStream method
  4. The output QR code can be seen below

Output

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 9 - Output: QR code image generated using QRCoder library.

IronQR

The following code shows how to generate QR code using IronQR:

using IronQr;
using IronSoftware.Drawing;
namespace QrCodeWithIronQR
{
public class Program
{
    public static void Main()
    {
            // Prepare a QR Code object
            QrCode theQrGen = QrWriter.Write("Awesome IronQR");
            // Save QR Code to memory
            AnyBitmap myQrImage = theQrGen.Save();
            // Save QR Code image to disk
            myQrImage.SaveAs("awesome.png");
        }
    }
}
using IronQr;
using IronSoftware.Drawing;
namespace QrCodeWithIronQR
{
public class Program
{
    public static void Main()
    {
            // Prepare a QR Code object
            QrCode theQrGen = QrWriter.Write("Awesome IronQR");
            // Save QR Code to memory
            AnyBitmap myQrImage = theQrGen.Save();
            // Save QR Code image to disk
            myQrImage.SaveAs("awesome.png");
        }
    }
}
Imports IronQr
Imports IronSoftware.Drawing
Namespace QrCodeWithIronQR
Public Class Program
	Public Shared Sub Main()
			' Prepare a QR Code object
			Dim theQrGen As QrCode = QrWriter.Write("Awesome IronQR")
			' Save QR Code to memory
			Dim myQrImage As AnyBitmap = theQrGen.Save()
			' Save QR Code image to disk
			myQrImage.SaveAs("awesome.png")
	End Sub
End Class
End Namespace
VB   C#

As you can already see the difference in the amount of code. IronQR code generation requires less code.

Code Explanation

  1. We create QR code using QrWriter.Write() method and passing the content.
  2. Then save QR code to memory using the Save() method.
  3. Last, we save the image using SaveAs() method;

Output

The output has an IronQR watermark since I am using a trial version of the library. With a licensed version, this will be removed.

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 10 - Output: QR code image generated using IronQR

Step 4 : Customization Options with QRCoder and IronQR

Both libraries support customization options. Let's look at some options available

We can set the QR code colors in QRCoder like below:

using QRCoder;
using System.Drawing;
namespace QRCoderVsIronQR
{
public class Program
{
    public static void Main()
    {
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
            using (var qrCode = new QRCoder.BitmapByteQRCode(qrCodeData))
            {                
                var qrCodeImage = qrCode.GetGraphic(20, [255,0,0], [0,255, 0]); // can also use html hex color notation
                var file = Image.FromStream(new MemoryStream(qrCodeImage));
                file.Save("QrCoderDemo1.png");
            }
        }
    }
}
using QRCoder;
using System.Drawing;
namespace QRCoderVsIronQR
{
public class Program
{
    public static void Main()
    {
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
            using (var qrCode = new QRCoder.BitmapByteQRCode(qrCodeData))
            {                
                var qrCodeImage = qrCode.GetGraphic(20, [255,0,0], [0,255, 0]); // can also use html hex color notation
                var file = Image.FromStream(new MemoryStream(qrCodeImage));
                file.Save("QrCoderDemo1.png");
            }
        }
    }
}
Imports QRCoder
Imports System.Drawing
Namespace QRCoderVsIronQR
Public Class Program
	Public Shared Sub Main()
			Using qrGenerator As New QRCodeGenerator()
			Using qrCodeData As QRCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q)
			Using qrCode = New QRCoder.BitmapByteQRCode(qrCodeData)
				Dim qrCodeImage = qrCode.GetGraphic(20, (255,0,0), (0,255, 0)) ' can also use html hex color notation
				Dim file = Image.FromStream(New MemoryStream(qrCodeImage))
				file.Save("QrCoderDemo1.png")
			End Using
			End Using
			End Using
	End Sub
End Class
End Namespace
VB   C#

Code Explanation

  1. We create QRCodeGenerator and call the CreateQrCode method to generate QR code graphic
  2. Then we use the QRCoder.BitmapByteQRCode() method to get the byte array from the GetGraphic method
  3. In the GetGraphic we can set the background and line colors. We have used red [255,0,0] R,G,B color for line color and Green [0,255,0] for background.
  4. Then we save the byte stream as image using the Image.FromStream() method
  5. The output QR code can be seen below

Output

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 11 - Output: Colorful QR code image generated using QRCoder's customization features.

We can set colors for IronQR QR code generation like following code:

using IronQr;
using IronSoftware.Drawing;
namespace QrCodeWithIronQR
public class Program
{
    public static void Main()
    {
            // Set options
            QrOptions options = new QrOptions(QrErrorCorrectionLevel.Medium, 20);
            // Create QR
            QrCode myQr = QrWriter.Write("IronQR Generation Demo 1", options);
            // Style options
            AnyBitmap logoBmp = new AnyBitmap("logo.png");
            QrStyleOptions style = new QrStyleOptions
            {
                BackgroundColor = Color.Aqua,
                Dimensions = 300, // px
                Margins = 10, // px
                Color = Color.Red,
                Logo = new QrLogo
                {
                    Bitmap = logoBmp,
                    Width = 100,
                    Height = 100,
                    CornerRadius = 2
                }
            };
            // Save QR Code
            AnyBitmap qrImage = myQr.Save(style);
            // Save QR Code to local disk
            qrImage.SaveAs("advancedQr.png");
        }
    }
}
using IronQr;
using IronSoftware.Drawing;
namespace QrCodeWithIronQR
public class Program
{
    public static void Main()
    {
            // Set options
            QrOptions options = new QrOptions(QrErrorCorrectionLevel.Medium, 20);
            // Create QR
            QrCode myQr = QrWriter.Write("IronQR Generation Demo 1", options);
            // Style options
            AnyBitmap logoBmp = new AnyBitmap("logo.png");
            QrStyleOptions style = new QrStyleOptions
            {
                BackgroundColor = Color.Aqua,
                Dimensions = 300, // px
                Margins = 10, // px
                Color = Color.Red,
                Logo = new QrLogo
                {
                    Bitmap = logoBmp,
                    Width = 100,
                    Height = 100,
                    CornerRadius = 2
                }
            };
            // Save QR Code
            AnyBitmap qrImage = myQr.Save(style);
            // Save QR Code to local disk
            qrImage.SaveAs("advancedQr.png");
        }
    }
}
Imports IronQr
Imports IronSoftware.Drawing
namespace QrCodeWithIronQR Public Class Program
	Public Shared Sub Main()
			' Set options
			Dim options As New QrOptions(QrErrorCorrectionLevel.Medium, 20)
			' Create QR
			Dim myQr As QrCode = QrWriter.Write("IronQR Generation Demo 1", options)
			' Style options
			Dim logoBmp As New AnyBitmap("logo.png")
			Dim style As New QrStyleOptions With {
				.BackgroundColor = Color.Aqua,
				.Dimensions = 300,
				.Margins = 10,
				.Color = Color.Red,
				.Logo = New QrLogo With {
					.Bitmap = logoBmp,
					.Width = 100,
					.Height = 100,
					.CornerRadius = 2
				}
			}
			' Save QR Code
			Dim qrImage As AnyBitmap = myQr.Save(style)
			' Save QR Code to local disk
			qrImage.SaveAs("advancedQr.png")
	End Sub
End Class
}
VB   C#

With IronQR there are many customization options. In the above program we have tried to customize the background color, QR code color, margins. We can also set dimensions.

Code Explanation

  1. First, we create the option object to set the error correction level
  2. Then we prepare the QR code with QrWriter.Write() method
  3. Then we set the style options with QrStyleOptions
  4. We set the background color, foreground color, margins, dimensions and also a logo to the QR code
  5. Then we save the QR code image to the local disk.

Output

How to Generate QR code using QRCoder compare to IronQR in .NET 6: Figure 12 - Output: Colorful QR code image generated using IronQR and its customization features.

Licensing

QRCoder is a MIT license-based package and is developed with the help of the community. This package is good for small-budget projects. The user needs to wait for the community to resolve issues or can fix and push the code to the Git Repository with pull requests approved.

IronQR to be used in applications. It has backing from Iron Software.

IronQR which can be obtained. The obtained key needs to be placed in the appSettings.json file here:

{
   "IronQR.License.LicenseKey":"myKey"
}
{
   "IronQR.License.LicenseKey":"myKey"
}
If True Then
   "IronQR.License.LicenseKey":"myKey"
End If
VB   C#

Conclusion

Choosing between C# QRCoder and IronQR ultimately depends on the specific requirements of your project. If you need a free and open source QR code generation library with a lot of customization options, then C# QRCoder might be the preferred choice due to its simplicity and extensive customization options.

If you need an enterprise-level library that supports not only QR code generation with customization options but also supports QR code reading, then IronQR would be the ultimate choice. So ultimately, with IronQR library, its many benefits and support functionality from Iron Software, developers can write enterprise applications with ease and peace of mind.

< PREVIOUS
How to Create a QR Code Generator Application In C#
NEXT >
How to Generate QR Code in VB .NET

Ready to get started? Version: 2024.11 just released

Free NuGet Download Total downloads: 21,819 View Licenses >