QRCoderを使ったQRコード生成と.NET 6でのIronQRの比較
C#でのQRコード生成
C#アプリケーションでQRコードを生成することは、特に製品識別、チケット発行、またはURLやその他のデータを簡単に共有するアプリケーションにおいて各開発者にとって共通の要件です。 C#でQRコードを生成するためのライブラリはいくつかあります。 注目すべき選択肢にはQRCoderとIronQRがあります。 ここでは、.NET 6で作業する開発者にとって関連する能力、使いやすさ、パフォーマンス、その他の要素を比較しながら、これら両方を探究します。この記事では、これらのライブラリの詳細な比較を行い、その機能、使いやすさ、ライセンスなどについて検討し、使用事例を示します。
.NET 6でIronQRと比較したQRCoderを使用してQRコードを生成する方法
- QRコードを生成するための新しいVisual Studioプロジェクトを作成する
- QRCoderとIronQRのNuGetパッケージをインストールして比較する
- QRCoderとIronQRを使用してQRコードを作成する
- QRCoderとIronQRでのカスタマイズオプション
QRCoder
QRCoderはC#で記述されたオープンソースライブラリで、任意 for .NETアプリケーションでISO/IEC 18004で定義されたQRコードを生成する機能を提供します。 他のライブラリやネットワークスタックへの依存無しで軽量かつ使いやすいライブラリです。
以下はQRCoderの主な機能と利点です。
1. 使いやすさ
C# QRCoderは直感的で使いやすいAPIを提供し、開発者が最小限の手間でQRコード/QRコードテキストを生成することを可能にします。 そのシンプルさにより、すべてのスキルレベルの開発者がプロジェクトにQRコード生成を迅速に統合できます。
2. 豊富なカスタマイズオプション
QRCoderの際立った機能の一つは、特定の要件に応じてQRコードをカスタマイズできることです。 開発者は誤り訂正レベル、サイズ、色、さらにはQRコード内にロゴや画像を埋め込むことも調整できます。
3. 複数のエンコード形式
QRCoderはさまざまなエンコード形式をサポートしており、開発者がさまざまなタイプのデータをQRコードにエンコードすることができます。 プレーンテキスト、URL、連絡先情報、Wi-Fi認証情報など、QRCoderは幅広いデータ形式に対応できます。
4. 高品質な出力
C# QRCoderが生成するQRコードは高品質で、さまざまなデバイスやスキャン条件での可読性と信頼性を保証します。 この信頼性は、QRコードが物理的およびデジタルの双方のやり取りの橋渡しとして機能するアプリケーションにとって重要です。
5. オープンソースと積極的な開発
C# QRCoderはオープンソースプロジェクトであり、開発者がその開発に貢献し、継続的な改善と更新を確保しています。 この活発なコミュニティの関与は革新を促進し、技術の変化に富む状況でもライブラリが時代に合ったものとなるよう保証します。
IronQR
IronQRはIron Softwareが開発し、維持している強力なC# QRコードライブラリです。 C#ソフトウェアエンジニアが.NETアプリケーションやウェブサイト内でQRコードの検出、読み取り、作成を行うことを可能にします。 以下はIronQRの主な特徴です。
QRコード生成
IronQRは非常にカスタマイズ可能なQRコード生成を実現します。 サイズ変更、マージン、ボーダー、再カラーリングなどの様々なオプションを用いてQRコードを作成できます。
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 ClassImports 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 ClassQRコードの読み取り
IronQRはQRコード検出のために高度な機械学習モデルを使用しています。 このモデルは正確で高速なQRコード読み取りを保証します。 IronQRはJPG、PNG、SVG、bmp、gifやtiffのようなマルチページ画像など、さまざまな画像形式からのQRコード読み取りをサポートしています。
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 ClassImports 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クロスプラットフォーム互換性
- デスクトップ: Windowsデスクトップアプリケーション(WPF & MAUI)で動作します。
- モバイル: XamarinとMAUIと互換性があります。
- ウェブ: BlazorとWebFormsをサポートします。
- コンソール: アプリとライブラリ環境。
- クラウド: Docker、Azure、およびAWS。
データのエンコード
テキスト、URL、バイト、数字など、QRコードにさまざまな種類のデータをエンコードできます。
誤り訂正
IronQRは詳細なエラーメッセージとカスタム誤り訂正オプションを提供します。
数百万人の信頼を集めるIronQRは、その信頼性と使いやすさで世界中のエンジニアに信頼されています。 IronQRを始めるには、NuGetを通してインストールできます。
ステップ1: QRコードを生成するための新しいVisual Studioプロジェクトを作成する
コードを始めるには、Visual Studio プロジェクトを作成します。 Microsoft Visual Studio 2022を開き、"新しいプロジェクトを作成"オプションを選択します。

テンプレートリストからコンソールアプリケーションテンプレートを選択します

次に、プロジェクト名とソリューション名を入力します。 プロジェクトファイルの保存先を選択します

必要な.NETバージョンを選択します。 この記事を書いている時点では最新 for .NET 8フレームワークを使用します。

作成ボタンをクリックすると、プロジェクトが作成され開発準備が整います。
ステップ2: QRCoderとIronQRのNuGetパッケージをインストールする
QRCoder NuGetパッケージは、以下に示すようにVisual Studio NuGetパッケージマネージャを使用してインストールできます。

または、NuGetパッケージマネージャコンソールから次のコマンドを使用してインストールします
QRCoder NuGetパッケージはここでNuGetウェブサイトから入手できます

IronQRも以下のVisual Studio NuGetパッケージマネージャでインストール可能です。

また、NuGetパッケージマネージャコンソールから次のコマンドを使用してインストールします

ステップ3: QRCoderとIronQRを使用してQRコードを作成する
2つのライブラリでQRコードを作成するには簡単なコードを必要とします、それらを確認しましょう
QRCoder
次のコードはQRCoderを使用して最初のQRコードを生成する方法を示しています
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 NamespaceImports 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コードの説明
CreateQrCodeメソッドを呼び出します。GetGraphicメソッドを使用してバイト配列を生成します。Image.FromStreamを使用してバイト配列を画像に変換します。- 生成された画像をディスクに保存します。
出力

IronQR
次のコードはIronQRを使用してQRコードを生成する方法を示しています。
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 NamespaceImports 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既にコード量の違いが見えます。 IronQRコード生成はより少ないコードを必要とします。
コードの説明
- 希望するコンテンツを渡して
QrWriter.Writeメソッドを使用してQRコードを作成します。 Saveメソッドを使用してQRコードをメモリに保存します。SaveAsを使用してQRコード画像をディスクに保存します。
出力
出力にはIronQRの透かしが入っていますが、これはライブラリの試用版を使用しているためです。 ライセンス版を使用すればこれは除去されます。

ステップ4: QRCoderとIronQRでのカスタマイズオプション
両方のライブラリはカスタマイズオプションをサポートしています。 利用可能なオプションのいくつかを見てみましょう
QRCoderで以下のようにQRコードの色を設定できます。
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 NamespaceImports 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コードの説明
CreateQrCodeメソッドを呼び出します。GetGraphicメソッドを使用してバイト配列を生成し、前景色(赤)と背景色(緑)を指定します。Image.FromStreamを使用してバイト配列を画像に変換します。- 生成された画像をディスクに保存します。
出力

IronQR QRコード生成用に以下のコードのような色を設定できます。
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 NamespaceImports 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 NamespaceIronQRには多くのカスタマイズオプションがあります。 上記のプログラムで、背景色、QRコード色、マージンのカスタマイズを試みました。 寸法も設定できます。
コードの説明
- エラー訂正レベルを設定するために
QrOptionsオブジェクトを最初に作成します。 QrWriter.WriteメソッドでQRコードを準備します。QrStyleOptionsを使用してスタイルオプションを設定します。- QRコードの背景色、前景色、マージン、寸法、およびロゴすら設定します。
- QRコード画像をローカルディスクに保存します。
出力

ライセンス
QRCoderはMITライセンスに基づくパッケージであり、コミュニティの助けを借りて開発されています。 このパッケージは小規模予算のプロジェクトに適しています。 ユーザーはコミュニティが問題を解決するのを待つ必要があるか、修正してGitリポジトリにプッシュしてプルリクエストの承認を得ることができます。
IronQRはライセンスが必要です。 これはIron Softwareにより支えられています。
いぬかIronQR試用版ライセンスを取得できます。 取得されたキーはここでappSettings.jsonファイルに配置する必要があります。
{
"IronQr.License.LicenseKey": "myKey"
}
結論
C# QRCoderとIronQR間での選択は、最終的にはプロジェクトの特定の要件に依存します。 無料でオープンソースのQRコード生成ライブラリが必要で、カスタマイズオプションが豊富な場合、C# QRCoderはその単純さと広範なカスタマイズオプションのために好ましい選択肢となる可能性があります。
一方、カスタマイズ可能なQRコード生成だけでなく、QRコード読み取りもサポートするエンタープライズレベルのライブラリが必要な場合、IronQRが最終的な選択となるでしょう。IronQRライブラリ、その多くの利点、およびIron Softwareによるサポート機能を備えたことで、開発者は安心してエンタープライズアプリケーションを書けます。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事

