Jak generować kody QR używając QRCoder w porównaniu do IronQR w .NET 6
Generowanie kodów QR w języku C
Tworzenie kodów QR w aplikacjach C# jest częstym wymaganiem programistów, zwłaszcza w przypadku aplikacji związanych z identyfikacją produktów, wystawianiem biletów lub łatwym udostępnianiem adresów URL i innych danych. Istnieje kilka bibliotek do generowania kodów QR w języku C#. Dwie godne uwagi opcje to QRCoder i IronQR. W tym artykułe przyjrzymy się obu bibliotekom, porównując ich możliwości, łatwość użycia, wydajność i inne czynniki istotne dla programistów pracujących z .NET 6. W tym artykułe zagłębimy się w szczegółowe porównanie tych bibliotek, analizując ich funkcje, łatwość użycia, licencję i inne aspekty, a także przedstawimy przykłady kodu ilustrujące ich zastosowanie.
Jak wygenerować kod QR za pomocą QRCoder w porównaniu z IronQR w .NET 6
- Utwórz nowy projekt w Visual Studio, aby wygenerować kod QR
- Zainstaluj pakiety NuGet QRCoder i IronQR, aby porównać
- Tworzenie kodów QR za pomocą QRCoder i IronQR
- Opcje dostosowywania za pomocą QRCoder i IronQR
QRCoder
QRCoder to biblioteka open source napisana w języku C#, która zapewnia implementację kodów QR, umożliwiającą generowanie kodów QR zgodnie z normą ISO/IEC 18004 w dowolnej aplikacji .NET. Jest to lekka i łatwa w użyciu biblioteka, która nie jest zależna od innych bibliotek ani stosów sieciowych.
Oto kluczowe funkcje i zalety QRCoder:
1. Łatwość użytkowania
C# QRCoder oferuje proste i intuicyjne API, ułatwiające programistom generowanie kodów QR/tekstu kodów QR przy minimalnym wysiłku. Jego prostota pozwala programistom o każdym poziomie umiejętności szybko zintegrować generowanie kodów QR ze swoimi projektami.
2. Szerokie możliwości dostosowania
Jedną z wyróżniających się funkcji QRCoder jest możliwość dostosowywania kodów QR do konkretnych wymagań. Programiści mogą dostosować parametry, takie jak poziom korekcji błędów, rozmiar, kolor, a nawet osadzić logo lub obrazy w kodzie QR.
3. Wiele formatów kodowania
QRCoder obsługuje różne formaty kodowania, umożliwiając programistom kodowanie różnych typów danych w kodach QR. Niezależnie od tego, czy chodzi o zwykły tekst, adresy URL, dane kontaktowe czy dane logowania do sieci Wi-Fi, QRCoder obsługuje szeroki zakres formatów danych.
4. Wysoka jakość tłumaczenia
Kody QR generowane przez C# QRCoder są wysokiej jakości, co zapewnia ich czytelność i niezawodność na różnych urządzeniach i w różnych warunkach skanowania. Ta niezawodność ma kluczowe znaczenie w przypadku aplikacji, w których kody QR służą jako pomost między interakcjami fizycznymi a cyfrowymi.
5. Oprogramowanie open source i aktywny rozwój
C# QRCoder to projekt open source, który pozwala programistom wnosić swój wkład w jego rozwój oraz zapewnia ciągłe ulepszenia i aktualizacje. To aktywne zaangażowanie społeczności sprzyja innowacjom i gwarantuje, że biblioteka pozostaje aktualna w nieustannie zmieniającym się świecie technologii.
IronQR
IronQR to potężna biblioteka kodów QR w języku C#, opracowana i utrzymywana przez Iron Software. Umożliwia to inżynierom oprogramowania C# wykrywanie, odczytywanie i tworzenie kodów QR w aplikacjach .NET i na stronach internetowych. Here are some key features of IronQR:
Generowanie kodów QR
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;
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;
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
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
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;
public class Program
{
public static void Main()
{
// 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 and get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);
}
}
using IronQr;
using IronSoftware.Drawing;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
// 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 and get all embedded QR Codes
IEnumerable<QrResult> results = reader.Read(imageInput);
}
}
Imports IronQr
Imports IronSoftware.Drawing
Imports System.Collections.Generic
Public Class Program
Public Shared Sub Main()
' Read QR code
Dim inputBmp = AnyBitmap.FromFile("awesome.png")
' Load the image into QrImageInput
Dim imageInput As New QrImageInput(inputBmp)
' Create the QR Reader object
Dim reader As New QrReader()
' Read the Input and get all embedded QR Codes
Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)
End Sub
End Class
Kompatybilność międzyplatformowa
- Desktop: Works with Windows desktop applications (WPF & MAUI).
- Mobile: Compatible with Xamarin and MAUI.
- Web: Supports Blazor and WebForms.
- Console: App and library environments.
- Cloud: Docker, Azure, and AWS.
Encoding Data
You can encode various types of data in QR codes, including text, URLs, bytes, and numbers.
Korekcja błędów
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.
Step 1: 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.

Select the Console application template from the template list

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

Wybierz wymagańą wersję .NET. I will go with the latest .NET 8 framework at the time of writing this article.

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.

Or install it from NuGet package manager console using the following command
dotnet add package QRCoder --version 1.4.3
The QRCoder NuGet package is available on the NuGet website here

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

Also from the NuGet package manager console, use the following command
dotnet add package IronQR --version 2024.4.1

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;
using System.IO;
namespace QRCoderVsIronQR
{
public class Program
{
public static void Main()
{
// Initialize QRCodeGenerator
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
// Create QR code data
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
// Initialize the QR code with the data
using (BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData))
{
// Generate the QR code's graphic and store it in a byte array
byte[] qrCodeImage = qrCode.GetGraphic(20);
// Convert the byte array to an image format and save it to disk
using (var file = Image.FromStream(new MemoryStream(qrCodeImage)))
{
file.Save("QrCoderDemo1.png");
}
}
}
}
}
using QRCoder;
using System.Drawing;
using System.IO;
namespace QRCoderVsIronQR
{
public class Program
{
public static void Main()
{
// Initialize QRCodeGenerator
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
// Create QR code data
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
// Initialize the QR code with the data
using (BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData))
{
// Generate the QR code's graphic and store it in a byte array
byte[] qrCodeImage = qrCode.GetGraphic(20);
// Convert the byte array to an image format and save it to disk
using (var file = Image.FromStream(new MemoryStream(qrCodeImage)))
{
file.Save("QrCoderDemo1.png");
}
}
}
}
}
Imports QRCoder
Imports System.Drawing
Imports System.IO
Namespace QRCoderVsIronQR
Public Class Program
Public Shared Sub Main()
' Initialize QRCodeGenerator
Using qrGenerator As New QRCodeGenerator()
' Create QR code data
Using qrCodeData As QRCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q)
' Initialize the QR code with the data
Using qrCode As New BitmapByteQRCode(qrCodeData)
' Generate the QR code's graphic and store it in a byte array
Dim qrCodeImage() As Byte = qrCode.GetGraphic(20)
' Convert the byte array to an image format and save it to disk
Using file = Image.FromStream(New MemoryStream(qrCodeImage))
file.Save("QrCoderDemo1.png")
End Using
End Using
End Using
End Using
End Sub
End Class
End Namespace
Wyjaśnienie kodu
- Initialize the
QRCodeGeneratorand call theCreateQrCodemethod to generate QR code data. - Use the
BitmapByteQRCodeclass to generate a byte array from the QR code data using theGetGraphicmethod. - Convert the byte array to an image using
Image.FromStream. - Save the generated image to disk.
Wynik

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
As you can already see the difference in the amount of code. IronQR code generation requires less code.
Wyjaśnienie kodu
- Create the QR code using the
QrWriter.Writemethod, passing the desired content. - Save the QR code to memory using the
Savemethod. - Save the QR code image to disk using
SaveAs.
Wynik
The output has an IronQR watermark since I am using a trial version of the library. With a licensed version, this will be removed.

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;
using System.IO;
namespace QRCoderVsIronQR
{
public class Program
{
public static void Main()
{
// Initialize QRCodeGenerator
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
// Create QR code data
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
// Initialize the QR code with the data
using (BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData))
{
// Generate the QR code's graphic, specifying foreground and background colors
byte[] qrCodeImage = qrCode.GetGraphic(20, Color.Red, Color.Green);
// Convert the byte array to an image format and save it to disk
using (var file = Image.FromStream(new MemoryStream(qrCodeImage)))
{
file.Save("QrCoderDemo1.png");
}
}
}
}
}
using QRCoder;
using System.Drawing;
using System.IO;
namespace QRCoderVsIronQR
{
public class Program
{
public static void Main()
{
// Initialize QRCodeGenerator
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
// Create QR code data
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q))
// Initialize the QR code with the data
using (BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData))
{
// Generate the QR code's graphic, specifying foreground and background colors
byte[] qrCodeImage = qrCode.GetGraphic(20, Color.Red, Color.Green);
// Convert the byte array to an image format and save it to disk
using (var file = Image.FromStream(new MemoryStream(qrCodeImage)))
{
file.Save("QrCoderDemo1.png");
}
}
}
}
}
Imports QRCoder
Imports System.Drawing
Imports System.IO
Namespace QRCoderVsIronQR
Public Class Program
Public Shared Sub Main()
' Initialize QRCodeGenerator
Using qrGenerator As New QRCodeGenerator()
' Create QR code data
Using qrCodeData As QRCodeData = qrGenerator.CreateQrCode("QRCoder Demo 1", QRCodeGenerator.ECCLevel.Q)
' Initialize the QR code with the data
Using qrCode As New BitmapByteQRCode(qrCodeData)
' Generate the QR code's graphic, specifying foreground and background colors
Dim qrCodeImage() As Byte = qrCode.GetGraphic(20, Color.Red, Color.Green)
' Convert the byte array to an image format and save it to disk
Using file = Image.FromStream(New MemoryStream(qrCodeImage))
file.Save("QrCoderDemo1.png")
End Using
End Using
End Using
End Using
End Sub
End Class
End Namespace
Wyjaśnienie kodu
- Initialize the
QRCodeGeneratorand call theCreateQrCodemethod to generate QR code data. - Use the
BitmapByteQRCodeclass to generate a byte array from the QR code data using theGetGraphicmethod, specifying the foreground (red) and background (green) colors. - Convert the byte array to an image using
Image.FromStream. - Save the generated image to disk.
Wynik

We can set colors for IronQR QR code generation like following code:
using IronQr;
using IronSoftware.Drawing;
using System.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;
using System.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
Imports System.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
End Namespace
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.
Wyjaśnienie kodu
- First, create the
QrOptionsobject to set the error correction level. - Prepare the QR code with
QrWriter.Writemethod. - Set the style options with
QrStyleOptions. - Set the background color, foreground color, margins, dimensions, and even a logo for the QR code.
- Save the QR code image to the local disk.
Wynik

Licencjonowanie
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 requires a license. It has backing from Iron Software.
A IronQR trial license can be obtained. The obtained key needs to be placed in the appSettings.json file here:
{
"IronQr.License.LicenseKey": "myKey"
}
Wnioski
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. With the IronQR library, its many benefits, and support functionality from Iron Software, developers can write enterprise applications with ease and peace of mind.
Często Zadawane Pytania
Jak mogę generować kody QR w C#?
Można wygenerować kody QR w C# używając bibliotek takich jak QRCoder i IronQR. QRCoder jest oprogramowaniem open-source i oferuje szerokie możliwości dostosowywania, a IronQR zapewnia zaawansowane funkcje i wsparcie wieloplatformowe, idealne dla aplikacji na poziomie enterprise.
Jakie są korzyści z używania QRCoder w projektach .NET 6?
QRCoder jest korzystny dla projektów .NET 6 ze względu na łatwość użycia, szerokie opcje dostosowywania i wsparcie dla wielu formatów kodowania. Jest również bezpłatny na licencji MIT, co czyni go odpowiednim dla projektów z ograniczonym budżetem.
Jak mogę dostosować kody QR używając IronQR?
IronQR pozwala programistom na dostosowanie kodów QR poprzez regulację parametrów takich jak kolor tła, kolor kodu QR, marginesy, wymiary, a nawet dodawanie logo, aby poprawić wygląd kodu QR.
Jaka jest zaleta stosowania IronQR w aplikacjach wieloplatformowych?
IronQR wspiera aplikacje wieloplatformowe w tym desktopowe (WPF i MAUI), mobilne (Xamarin i MAUI), webowe (Blazor i WebForms), aplikacje konsolowe i środowiska chmurowe jak Docker, Azure i AWS, co czyni go idealnym dla różnorodnych potrzeb deweloperskich.
Jakie kroki są potrzebne do założenia projektu generowania kodu QR w Visual Studio?
Aby założyć projekt generowania kodu QR w Visual Studio, należy zainstalować niezbędne pakiety NuGet dla QRCoder lub IronQR, w zależności od wyboru. Artykuł zawiera instrukcje krok po kroku i przykłady kodu, które poprowadzą przez cały proces.
Jak IronQR ulepsza korekcję błędów kodu QR?
IronQR ulepsza korekcję błędów kodu QR, oferując szczegółowe opcje zapewniające dokładne odczytywanie nawet wtedy, gdy kod QR jest uszkodzony lub częściowo zasłonięty. Dzięki temu jest bardzo niezawodny w zastosowaniach krytycznych.
Jakie są dostępne opcje licencjonowania dla IronQR?
IronQR wymaga komercyjnej licencji, wspieranej przez Iron Software, z opcją uzyskania licencji próbnej do celów ewaluacyjnych. To zapewnia, że projekty na poziomie enterprise mają dostęp do solidnego wsparcia i funkcji.
Którą bibliotekę powinienem wybrać do prostego projektu z kodami QR?
Do prostych projektów z kodami QR zalecany jest QRCoder ze względu na jego prostotę, łatwość użycia i opłacalność, będąc biblioteką open-source na licencji MIT.
Czy IronQR może odczytywać kody QR z różnych formatów obrazów?
Tak, IronQR może odczytywać kody QR z różnych formatów obrazów, wykorzystując zaawansowany model uczenia maszynowego, aby zapewnić szybkie i dokładne odczyty na różnych platformach.




