C#でQRコードを生成する - .NET開発者向けの完全チュートリアル
C#アプリケーションでQRコードを生成する必要がありますか? このチュートリアルでは、IronBarcodeを使用してQRコードを作成、カスタマイズ、検証する方法を詳細に示します。シンプルな一行の実装から、ロゴの埋め込みやバイナリデータのエンコーディングなどの高度な機能まであります。
在庫管理システム、イベントのチケットプラットフォーム、または非接触決済ソリューションを構築しているかどうかにかかわらず、.NETアプリケーションでプロフェッショナルなQRコード機能を実装する方法を学びます。
クイックスタート: IronBarcodeを使用した一行でのQRコード生成
速くQRコードを生成する準備はできましたか?IronBarcodeのQRCodeWriter APIを使って、たった一行のコードでQRコードを生成する方法をご覧ください。カスタマイズはオプションですが強力です。
今すぐ NuGet で PDF を作成してみましょう:
NuGet パッケージ マネージャーを使用して IronBarcode をインストールします
このコード スニペットをコピーして実行します。
var qr = QRCodeWriter.CreateQrCode("https://ironsoftware.com/", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium); qr.SaveAsPng("MyQR.png");実際の環境でテストするためにデプロイする
最小限のワークフロー(5ステップ)
- NuGet経由でIronBarcodeをインストールする
- Create a QR code with one line: `QRCodeWriter.CreateQrCode()`
- Embed logos using `CreateQrCodeWithLogo()`
- Verify readability with `GeneratedBarcode.Verify()`
- 高度なアプリケーション向けにバイナリデータをエンコードする
C#でQRコードライブラリをインストールするにはどうすればよいですか?
今日あなたのプロジェクトでIronBarcodeを無料トライアルで使用開始。
このシンプルなコマンドでNuGetパッケージマネージャを使用してIronBarcodeをインストールしてください:
Install-Package BarCode
または、IronBarcode DLLを直接ダウンロードしてプロジェクトの参照として追加してください。
必要な名前空間をインポートする
IronBarcodeのQRコード生成機能にアクセスするためにこれらの名前空間を追加してください:
using IronBarCode;
using System;
using System.Drawing;
using System.Linq;using IronBarCode;
using System;
using System.Drawing;
using System.Linq;Imports IronBarCode
Imports System
Imports System.Drawing
Imports System.LinqC#でシンプルなQRコードを作成するにはどうすればよいですか?
IronBarcodeのCreateQrCodeメソッドを使用して、たった一行のコードでQRコードを生成します:
using IronBarCode;
// Generate a QR code with text content
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium);
qrCode.SaveAsPng("MyQR.png");using IronBarCode;
// Generate a QR code with text content
var qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium);
qrCode.SaveAsPng("MyQR.png");Imports IronBarCode
' Generate a QR code with text content
Private qrCode = QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium)
qrCode.SaveAsPng("MyQR.png")CreateQrCodeメソッドは3つのパラメータを受け入れます:
- テキスト内容:エンコードするデータ(URL、テキスト、その他の文字列データをサポート)
- サイズ:正方形のQRコードのピクセル寸法(この例では500x500)
- エラー訂正:不都合な条件での可読性を決定(低、中、クォータイル、高)
エラー訂正レベルが高いほど、QRコードが部分的に損傷または隠れている場合でも読み取り可能であることを保証しますが、データモジュールが多くなりより密度の高いパターンが生じます。
"hello world"というテキストを含む基本QRコード、500x500ピクセルで中エラー訂正で生成されています
QRコードにロゴを追加するにはどうしたらよいですか?
QRコードにロゴを埋め込むことで、ブランド認知を高めつつスキャン可能性を保ちます。 IronBarcodeはQRコードの整合性を保持するためにロゴを自動的に位置決めし、サイズ調整します:
using IronBarCode;
using IronSoftware.Drawing;
// Load logo image
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
// Create QR code with embedded logo
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
// Save the branded QR code
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png");using IronBarCode;
using IronSoftware.Drawing;
// Load logo image
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
// Create QR code with embedded logo
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
// Save the branded QR code
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png");Imports IronBarCode
Imports IronSoftware.Drawing
' Load logo image
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
' Create QR code with embedded logo
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
' Customize appearance
myQRCodeWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen)
' Save the branded QR code
myQRCodeWithLogo.SaveAsPng("myQRWithLogo.png")CreateQrCodeWithLogoメソッドは、ロゴの配置を賢く処理します:
- QRコードの読取り可能性を維持するためにロゴを自動的にサイズ変更
- データ破損を避けるため静止域内に位置決め
- QRコードの色を変更してもロゴの元の色を保持
このアプローチにより、ブランド化されたQRコードがすべてのスキャニングデバイスやアプリケーションで完全に動作することを保証します。
Visual StudioロゴをフィーチャーしたQRコード、IronBarcodeの自動ロゴサイズ調整と位置決めを示しています
QRコードを異なる形式にエクスポートするにはどうすればいいですか?
IronBarcodeは、さまざまな使用用途に対応した複数のエクスポート形式をサポートしています。 QRコードを画像、PDF、またはHTMLファイルとしてエクスポートします:
using IronBarCode;
using System.Drawing;
// Create QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen);
// Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf"); // PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html"); // Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png"); // PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg"); // JPEG imageusing IronBarCode;
using System.Drawing;
// Create QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myQRCodeWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen);
// Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf"); // PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html"); // Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png"); // PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg"); // JPEG imageImports IronBarCode
Imports System.Drawing
' Create QR code with logo
Private qrCodeLogo As New QRCodeLogo("visual-studio-logo.png")
Private myQRCodeWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo)
' Apply custom styling
myQRCodeWithLogo.ChangeBarCodeColor(Color.DarkGreen)
' Export to multiple formats
myQRCodeWithLogo.SaveAsPdf("MyQRWithLogo.pdf") ' PDF document
myQRCodeWithLogo.SaveAsHtmlFile("MyQRWithLogo.html") ' Standalone HTML
myQRCodeWithLogo.SaveAsPng("MyQRWithLogo.png") ' PNG image
myQRCodeWithLogo.SaveAsJpeg("MyQRWithLogo.jpg") ' JPEG image各形式は特定の目的に適しています:
- PDF:印刷可能なドキュメントとレポートに最適
- HTML:外部依存なしでのWeb統合に最適
- PNG/JPEG:多目的使用に適した標準画像形式
カスタマイズ後のQRコードの読みやすさを検証する方法
色の変更やロゴの追加はQRコードのスキャン可能性に影響を与えることがあります。 Verify()メソッドを使用して、カスタマイズされたQRコードが読み取り可能なままであることを確認します:
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Drawing;
// Generate QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myVerifiedQR = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply light color (may affect readability)
myVerifiedQR.ChangeBarCodeColor(Color.LightBlue);
// Verify the QR code can still be scanned
if (!myVerifiedQR.Verify())
{
Console.WriteLine("LightBlue is not dark enough to be read accurately. Let's try DarkBlue");
myVerifiedQR.ChangeBarCodeColor(Color.DarkBlue);
}
// Save verified QR code
myVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html");using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Drawing;
// Generate QR code with logo
QRCodeLogo qrCodeLogo = new QRCodeLogo("visual-studio-logo.png");
GeneratedBarcode myVerifiedQR = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/", qrCodeLogo);
// Apply light color (may affect readability)
myVerifiedQR.ChangeBarCodeColor(Color.LightBlue);
// Verify the QR code can still be scanned
if (!myVerifiedQR.Verify())
{
Console.WriteLine("LightBlue is not dark enough to be read accurately. Let's try DarkBlue");
myVerifiedQR.ChangeBarCodeColor(Color.DarkBlue);
}
// Save verified QR code
myVerifiedQR.SaveAsHtmlFile("MyVerifiedQR.html");IRON VB CONVERTER ERROR developers@ironsoftware.comVerify()メソッドは、QRコードに対して包括的なスキャンテストを行います。 これにより、異なるスキャニングデバイスや照明条件に対応した互換性が確保されるため、配布前に確認が行えます。
ダークブルーでうまく検証されたQRコード、信頼できるスキャンを発揮する正しいコントラストを示す
QRコードにバイナリデータをエンコードするにはどうすればいいですか?
QRコードは、バイナリデータを効率的に格納するのに優れています。 この能力により、暗号化されたデータ転送、ファイル共有、IoTデバイスの設定など、高度なアプリケーションが可能になります:
using IronBarCode;
using System;
using System.Linq;
// Convert string to binary data
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/");
// Create QR code from binary content
QRCodeWriter.CreateQrCode(binaryData, 500).SaveAsPng("MyBinaryQR.png");
// Read and verify binary data integrity
var myReturnedData = BarcodeReader.Read("MyBinaryQR.png").First();
// Confirm data matches original
if (binaryData.SequenceEqual(myReturnedData.BinaryValue))
{
Console.WriteLine("Binary Data Read and Written Perfectly");
}
else
{
throw new Exception("Data integrity check failed");
}using IronBarCode;
using System;
using System.Linq;
// Convert string to binary data
byte[] binaryData = System.Text.Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/");
// Create QR code from binary content
QRCodeWriter.CreateQrCode(binaryData, 500).SaveAsPng("MyBinaryQR.png");
// Read and verify binary data integrity
var myReturnedData = BarcodeReader.Read("MyBinaryQR.png").First();
// Confirm data matches original
if (binaryData.SequenceEqual(myReturnedData.BinaryValue))
{
Console.WriteLine("Binary Data Read and Written Perfectly");
}
else
{
throw new Exception("Data integrity check failed");
}Imports IronBarCode
Imports System
Imports System.Linq
' Convert string to binary data
Private binaryData() As Byte = System.Text.Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/")
' Create QR code from binary content
QRCodeWriter.CreateQrCode(binaryData, 500).SaveAsPng("MyBinaryQR.png")
' Read and verify binary data integrity
Dim myReturnedData = BarcodeReader.Read("MyBinaryQR.png").First()
' Confirm data matches original
If binaryData.SequenceEqual(myReturnedData.BinaryValue) Then
Console.WriteLine("Binary Data Read and Written Perfectly")
Else
Throw New Exception("Data integrity check failed")
End IfQRコードのバイナリエンコーディングは、いくつかの利点を提供します:
- 効率性:コンパクトなバイナリ形式でデータを格納
- 多様性:あらゆるデータタイプ(ファイル、暗号化コンテンツ、シリアライズされたオブジェクト)を扱う
- 整合性:エンコードの問題なく正確なバイトシーケンスを保持
この機能により、IronBarcodeは基本的なQRコードライブラリとは異なり、アプリケーションにおける高度なデータ交換シナリオを可能にします。
IronBarcodeの高度なエンコード機能を示すバイナリデータを格納するQRコード。
C#でQRコードを読み取るにはどうすればいいですか?
IronBarcodeは柔軟なQRコード読み取り機能を提供しています。 最もシンプルなアプローチを紹介します:
using IronBarCode;
using System;
using System.Linq;
// Read QR code with optimized settings
BarcodeResults result = BarcodeReader.Read("QR.png", new BarcodeReaderOptions() {
ExpectBarcodeTypes = BarcodeEncoding.QRCode
});
// Extract and display the decoded value
if (result != null && result.Any())
{
Console.WriteLine(result.First().Value);
}
else
{
Console.WriteLine("No QR codes found in the image.");
}using IronBarCode;
using System;
using System.Linq;
// Read QR code with optimized settings
BarcodeResults result = BarcodeReader.Read("QR.png", new BarcodeReaderOptions() {
ExpectBarcodeTypes = BarcodeEncoding.QRCode
});
// Extract and display the decoded value
if (result != null && result.Any())
{
Console.WriteLine(result.First().Value);
}
else
{
Console.WriteLine("No QR codes found in the image.");
}Imports IronBarCode
Imports System
Imports System.Linq
' Read QR code with optimized settings
Private result As BarcodeResults = BarcodeReader.Read("QR.png", New BarcodeReaderOptions() With {.ExpectBarcodeTypes = BarcodeEncoding.QRCode})
' Extract and display the decoded value
If result IsNot Nothing AndAlso result.Any() Then
Console.WriteLine(result.First().Value)
Else
Console.WriteLine("No QR codes found in the image.")
End Ifより複雑なシナリオでの微調整コントロールが必要な場合:
using IronBarCode;
using System;
using System.Linq;
// Configure advanced reading options
BarcodeReaderOptions options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Faster, // Optimize for speed
ExpectMultipleBarcodes = false, // Single QR code expected
ExpectBarcodeTypes = BarcodeEncoding.QRCode, // QR codes only
Multithreaded = true, // Enable parallel processing
MaxParallelThreads = 4, // Utilize multiple CPU cores
RemoveFalsePositive = true, // Filter out false detections
ImageFilters = new ImageFilterCollection() // Apply preprocessing
{
new AdaptiveThresholdFilter(), // Handle varying lighting
new ContrastFilter(), // Enhance contrast
new SharpenFilter() // Improve edge definition
}
};
// Read with advanced configuration
BarcodeResults result = BarcodeReader.Read("QR.png", options);using IronBarCode;
using System;
using System.Linq;
// Configure advanced reading options
BarcodeReaderOptions options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Faster, // Optimize for speed
ExpectMultipleBarcodes = false, // Single QR code expected
ExpectBarcodeTypes = BarcodeEncoding.QRCode, // QR codes only
Multithreaded = true, // Enable parallel processing
MaxParallelThreads = 4, // Utilize multiple CPU cores
RemoveFalsePositive = true, // Filter out false detections
ImageFilters = new ImageFilterCollection() // Apply preprocessing
{
new AdaptiveThresholdFilter(), // Handle varying lighting
new ContrastFilter(), // Enhance contrast
new SharpenFilter() // Improve edge definition
}
};
// Read with advanced configuration
BarcodeResults result = BarcodeReader.Read("QR.png", options);Imports IronBarCode
Imports System
Imports System.Linq
' Configure advanced reading options
Private options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Faster,
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode,
.Multithreaded = True,
.MaxParallelThreads = 4,
.RemoveFalsePositive = True,
.ImageFilters = New ImageFilterCollection() From {
New AdaptiveThresholdFilter(),
New ContrastFilter(),
New SharpenFilter()
}
}
' Read with advanced configuration
Private result As BarcodeResults = BarcodeReader.Read("QR.png", options)これらの高度な読み取りオプションを使用すると、悪条件(悪照明、画像歪み、低品質印刷)でのQRコード検出が可能です。
QRコード開発の次は? IronBarcodeを使ったQRコードの生成をマスターしたので、これらの高度なトピックを探求してください: - [PDFドキュメントからQRコードを抽出する](/csharp/barcode/how-to/read-barcodes-from-pdf/) - [バッチQRコード処理を実装する](/csharp/barcode/tutorials/reading-barcodes/) - [難しいスキャンのための画像修正を適用する](/csharp/barcode/how-to/image-correction/) ### リソースをダウンロード 完全なソースコードと例にアクセスしてください: - [GitHub リポジトリ](https://github.com/iron-software/Iron-Barcode-Generating-QR-Codes-In-CSharp-Tutorial) - [ソースコードダウンロード](/downloads/assets/tutorials/creating-qr-barcodes-in-dot-net/Generating-QR-Codes-In-CSharp.zip) ### APIドキュメント APIリファレンスで完全な機能セットを探る: - [QRCodeWriterクラスリファレンス](/csharp/barcode/object-reference/api/IronBarCode.QRCodeWriter.html) - [BarcodeReaderクラスリファレンス](/csharp/barcode/object-reference/api/IronBarCode.BarcodeReader.html) - [GeneratedBarcodeクラスリファレンス](/csharp/barcode/object-reference/api/IronBarCode.GeneratedBarcode.html) ### 代替案: 高度なQRアプリケーション向けIronQR 最先端のQRコード機能を必要とするプロジェクトには、[IronQR](/csharp/qr/)-Iron SoftwareのQRコード専用ライブラリをご検討ください。機械学習による読み取り精度は99.99%で、高度な生成オプションを備えています。 .NETアプリケーションにQRコードを実装する準備ができましたか? [無料トライアルを開始](trial-license)または[IronBarcodeをダウンロード](download-modal)してください。
よくある質問
C#でQRコードを生成するにはどうすればよいですか?
C#でIronBarcodeのQRCodeWriter.CreateQrCode()メソッドを使用してQRコードを生成できます。このメソッドを使うことで、コンテンツ、サイズ、エラー訂正レベルを指定して効率的にQRコードを作成します。
QRコードはどの画像形式にエクスポートできますか?
IronBarcodeを使用すると、QRコードをPNG、JPEG、PDF、HTMLなどの様々な形式にエクスポートできます。この目的のために、SaveAsPng()、SaveAsJpeg()、SaveAsPdf()、SaveAsHtmlFile()などのメソッドが用意されています。
QRコードに会社のロゴをどのように追加できますか?
IronBarcodeはCreateQrCodeWithLogo()メソッドを提供しており、これにQRCodeLogoオブジェクトを渡すことで、ロゴ画像を含めることができます。ライブラリはロゴがQRコードの読み取り性を損なわないように正しくサイズや位置を調整します。
QRコードのエラー訂正とは何ですか?どのレベルを選べばよいですか?
QRコードのエラー訂正は、一部が損傷していてもスキャン可能であることを保証します。IronBarcodeは4つのレベルを提供しています:低(7%)、中(15%)、四分(25%)、高(30%)。ほとんどの用途には中レベルが適しており、厳しい環境には高レベルが理想的です。
カスタマイズされたQRコードの読み取り性をどのように確認しますか?
GeneratedBarcodeオブジェクトでVerify()メソッドを使用することで、色の変更やロゴ追加といった変更後もカスタマイズされたQRコードがスキャンできることを確認できます。
QRコードにバイナリデータをエンコードできますか?
はい、IronBarcodeのCreateQrCode()メソッドはバイト列のエンコードをサポートしており、ファイルや暗号化されたコンテンツをQRコード内に保存できます。
C#で画像からQRコードをどのように読み取りますか?
C#で画像からQRコードを読み取るには、IronBarcodeのBarcodeReader.Read()メソッドを利用します。パフォーマンスを最適化するために、BarcodeReaderOptionsでBarcodeEncoding.QRCodeを指定してください。
QRコードの最大データ容量はどれくらいですか?
IronBarcodeで生成されたQRコードは、選択したエラー訂正レベルに応じて最大で2,953バイト、4,296の英数字、または7,089の数字を保持できます。
QRコードの色を変更しても読み取り可能に保つにはどうすればよいですか?
IronBarcodeのChangeBarCodeColor()メソッドを使用してQRコードの色を変更できます。色の変更がQRコードの読み取り性に影響を及ぼさないことを確認するために、常にVerify()メソッドを使用してください。
特殊なQRコードライブラリにはどのような機能がありますか?
Iron Softwareの特殊なライブラリであるIronQRは、99.99%の精度で動作する機械学習を搭載したQRコード読み取り機能や、複雑なアプリケーションに対応した頑強な生成機能などの高度な機能を含んでいます。






