C# .NETアプリケーションでバーコード画像を生成する方法
.NETアプリケーションでプロフェッショナルなバーコード画像をすばやく生成する必要がありますか? このチュートリアルでは、IronBarcodeを使用して、シンプルな1行の実装から高度なスタイリング技術まで、バーコードの作成、カスタマイズ、エクスポート方法を正確に示します。
クイックスタート: バーコードイメージを即座に作成して保存する
IronBarcodeを使用すると、1つのシンプルな呼び出しでバーコード画像を生成してエクスポートできます。 テキストに CreateBarcode メソッドを使用し、形式とサイズを選択してから SaveAsPng を呼び出します。複雑な設定は必要ありません。
最小限のワークフロー(5ステップ)
- NuGet パッケージ マネージャー経由で IronBarcode をインストールする
- 1行のコードでシンプルなバーコードを生成する
- バーコードにカスタムスタイルと注釈を適用する
- バーコードを画像、PDF、HTMLとしてエクスポートする
- Fluent API を使用して効率的にバーコードを生成する
C#でバーコード生成ライブラリをインストールするには?
IronBarcodeのインストールは、NuGetパッケージマネージャーを使用して数秒で完了します。 パッケージマネージャーコンソールを通じて直接インストールするか、DLLを手動でダウンロードすることができます。
Install-Package BarCode
*IronBarcodeは、.NET開発者向けに包括的なバーコード生成機能を提供します。*
C#でシンプルなバーコードを生成するには?
最初のバーコードを作成するには、たった2行のコードが必要です。 以下の例は、標準のCode128バーコードを生成し、画像ファイルとして保存する方法を示しています。
using IronBarCode;
// Create a barcode with your desired content and encoding type
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
// Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png");
// Optional: Open the generated image in your default viewer
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("myBarcode.png") { UseShellExecute = true });
using IronBarCode;
// Create a barcode with your desired content and encoding type
GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
// Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png");
// Optional: Open the generated image in your default viewer
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("myBarcode.png") { UseShellExecute = true });
Imports IronBarCode
' Create a barcode with your desired content and encoding type
Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128)
' Save the barcode as a PNG image file
myBarcode.SaveAsPng("myBarcode.png")
' Optional: Open the generated image in your default viewer
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("myBarcode.png") With {.UseShellExecute = True})
BarcodeWriter.CreateBarcode() メソッドは、バーコード生成のエントリ ポイントです。 エンコードするデータと、BarcodeWriterEncoding 列挙型のバーコード形式の 2 つのパラメータを受け入れます。 IronBarcodeは、Code128、Code39、EAN13、UPC-A、PDF417、DataMatrix、QRコードを含むすべての主要なバーコードフォーマットをサポートしています。
生成されると、GeneratedBarcode オブジェクトには複数のエクスポート オプションが提供されます。 さまざまな画像形式 (PNG、JPEG、GIF、TIFF) で保存したり、PDF にエクスポートしたり、さらにはアプリケーションでさらに処理するために System.Drawing.Bitmap として取得することもできます。
*A Code128 barcode generated with IronBarcode displaying a URL*
生成されたバーコードの外観をカスタマイズできますか?
IronBarcodeは、基本的なバーコード生成を超えた広範なカスタマイズオプションを提供します。 注釈を追加したり、色を調整したり、余白を設定したり、バーコードの外観のすべての側面を制御できます。
using IronBarCode;
using IronSoftware.Drawing;
// Create a QR code with advanced styling options
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com/csharp/barcode",
BarcodeWriterEncoding.QRCode
);
// Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:");
// Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode();
// Set consistent margins around the barcode
myBarCode.SetMargins(100);
// Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple);
// Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html");
using IronBarCode;
using IronSoftware.Drawing;
// Create a QR code with advanced styling options
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode(
"https://ironsoftware.com/csharp/barcode",
BarcodeWriterEncoding.QRCode
);
// Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:");
// Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode();
// Set consistent margins around the barcode
myBarCode.SetMargins(100);
// Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple);
// Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html");
Imports IronBarCode
Imports IronSoftware.Drawing
' Create a QR code with advanced styling options
Private myBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode)
' Add descriptive text above the barcode
myBarCode.AddAnnotationTextAboveBarcode("Product URL:")
' Display the encoded value below the barcode
myBarCode.AddBarcodeValueTextBelowBarcode()
' Set consistent margins around the barcode
myBarCode.SetMargins(100)
' Customize the barcode color (purple in this example)
myBarCode.ChangeBarCodeColor(Color.Purple)
' Export as an HTML file for web integration
myBarCode.SaveAsHtmlFile("MyBarCode.html")
GeneratedBarcode クラスは、カスタマイズのための豊富なメソッドを提供します。
-注釈: バーコードの周囲にカスタムラベルや説明を追加するには、AddAnnotationTextAboveBarcode() と AddAnnotationTextBelowBarcode() を使用します。
-値の表示: AddBarcodeValueTextBelowBarcode()方式は、エンコードされたデータを人間が読める形式で自動的に表示します。
-スペース: 適切なスキャンと視覚的な魅力を確保するために、SetMargins() を使用して空白スペースを制御します。
-色: ChangeBarCodeColor() と ChangeBackgroundColor() を使用して前景色と背景色を変更します。
- エクスポートオプション: 画像ファイル、PDF、自己完結型HTMLドキュメントとして保存します
*カスタムカラーと注釈テキストを備えたスタイル付きQRコード*詳細なカスタマイズ オプションについては、使用可能なすべてのスタイル設定メソッドとプロパティを網羅したGeneratedBarcode クラスのドキュメントを参照してください。
1行のコードでバーコードを作成してエクスポートするにはどうすればよいですか?
このアプローチは、バーコードに複数の変換を適用する場合に特に便利です。 このアプローチは、バーコードに複数の変換を適用する場合に特に役立ちます。
using IronBarCode;
using IronSoftware.Drawing;
// Generate, style, and convert a barcode in a single statement
string value = "https://ironsoftware.com/csharp/barcode";
// Create PDF417 barcode with chained operations
AnyBitmap barcodeBitmap = BarcodeWriter
.CreateBarcode(value, BarcodeWriterEncoding.PDF417) // Create PDF417 barcode
.ResizeTo(300, 200) // Set specific dimensions
.SetMargins(10) // Add 10px margins
.ToBitmap(); // Convert to bitmap
// Convert to System.Drawing.Bitmap for legacy compatibility
System.Drawing.Bitmap legacyBitmap = barcodeBitmap;
using IronBarCode;
using IronSoftware.Drawing;
// Generate, style, and convert a barcode in a single statement
string value = "https://ironsoftware.com/csharp/barcode";
// Create PDF417 barcode with chained operations
AnyBitmap barcodeBitmap = BarcodeWriter
.CreateBarcode(value, BarcodeWriterEncoding.PDF417) // Create PDF417 barcode
.ResizeTo(300, 200) // Set specific dimensions
.SetMargins(10) // Add 10px margins
.ToBitmap(); // Convert to bitmap
// Convert to System.Drawing.Bitmap for legacy compatibility
System.Drawing.Bitmap legacyBitmap = barcodeBitmap;
Imports IronBarCode
Imports IronSoftware.Drawing
' Generate, style, and convert a barcode in a single statement
Private value As String = "https://ironsoftware.com/csharp/barcode"
' Create PDF417 barcode with chained operations
Private barcodeBitmap As AnyBitmap = BarcodeWriter.CreateBarcode(value, BarcodeWriterEncoding.PDF417).ResizeTo(300, 200).SetMargins(10).ToBitmap() ' Convert to bitmap
' Convert to System.Drawing.Bitmap for legacy compatibility
Private legacyBitmap As System.Drawing.Bitmap = barcodeBitmap
フルーエントAPIパターンは、いくつかの利点を提供します:
- 可読性: 自然言語のように読める論理的な順序で操作をチェーンできます
- 柔軟性: コードを再構成せずに操作を簡単に追加または削除できます
- 柔軟性: コードを再構築することなく、操作を簡単に追加または削除できます
一般的な流暢な操作には:
ResizeTo(): バーコードの正確な寸法を制御するSetMargins(): 一定の間隔を追加するChangeBarCodeColor(): 外観を変更するAddAnnotationTextAboveBarcode(): 説明テキストを含めるSaveAsPdf(): さまざまな形式でエクスポート
*A PDF417 barcode generated using fluent method chaining*
IronBarcodeはBarcodeWriterEncoding列挙型を通じて包括的なバーコードフォーマット生成をサポートしています。
IronBarcode は、BarcodeWriterEncoding 列挙型を通じて包括的なバーコード形式の生成をサポートします。 1Dバーコード: Code128, Code39, Code93, Codabar, ITF, MSI, Plessey, UPCA, UPCE, EAN8, EAN13
1次元バーコード:Code128、Code39、Code93、Codabar、ITF、MSI、Plessey、UPCA、UPCE、EAN8、EAN13 2次元バーコード:QRCode、DataMatrix、PDF417、Aztec、MaxiCode 特化したフォーマット: IntelligentMail、DataBar、DataBarExpanded、およびさまざまなGS1規格
各フォーマットには特定の特性と使用ケースがあります。 アプリケーションに最適なバーコードフォーマットを選ぶ方法については、こちらを参照してください。 ## 生成されたバーコードが読み取り可能であることをどう確認できますか?
生成したバーコードが読み取れるかどうかをどう確認できますか?
IronBarcodeには、生成されたバーコードがスキャン可能であることを確認するための組み込み検証機能が含まれています: IronBarcodeには、生成したバーコードがスキャン可能であることを確認するための組み込みの検証機能があります:
// Generate and verify a barcode
GeneratedBarcode myBarcode = BarcodeWriter
.CreateBarcode("TEST123", BarcodeWriterEncoding.Code128)
.ResizeTo(200, 100)
.ChangeBarCodeColor(Color.DarkBlue);
// Verify the barcode is still readable after modifications
bool isReadable = myBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
// Generate and verify a barcode
GeneratedBarcode myBarcode = BarcodeWriter
.CreateBarcode("TEST123", BarcodeWriterEncoding.Code128)
.ResizeTo(200, 100)
.ChangeBarCodeColor(Color.DarkBlue);
// Verify the barcode is still readable after modifications
bool isReadable = myBarcode.Verify();
Console.WriteLine($"Barcode verification: {(isReadable ? "PASS" : "FAIL")}");
' Generate and verify a barcode
Dim myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("TEST123", BarcodeWriterEncoding.Code128).ResizeTo(200, 100).ChangeBarCodeColor(Color.DarkBlue)
' Verify the barcode is still readable after modifications
Dim isReadable As Boolean = myBarcode.Verify()
Console.WriteLine($"Barcode verification: {(If(isReadable, "PASS", "FAIL"))}")
Verify() メソッドは、サイズ変更や色の変更などの変換を適用した後でもバーコードが機械で読み取り可能な状態であるかどうかを確認します。 特に、非標準の色や非常に小さなサイズを使用する際に重要です。
バーコード生成の例をもっと見つけるにはどこを探せばよいですか?
バーコード生成能力を拡張するために、これらの追加リソースを探索してください:
このチュートリアルの完全なソースコードをダウンロード:
-
高度なトピック
-
ロゴ付きQRコードを生成 - QRコードにブランドを追加
- Generate QR Codes with Logos - あなたのQRコードにブランディングを追加します。
- バーコードスタイリングガイド - 高度なカスタマイズテクニックをマスターしてください。
- 画像からバーコードを読み取る - バーコードスキャンでサイクルを完成させる
- バッチバーコード生成 - 複数のバーコードを効率的に生成します
APIドキュメント
BarcodeWriterクラスリファレンス- 完全なメソッドドキュメントGeneratedBarcodeクラスリファレンス- すべてのカスタマイズオプションBarcodeWriterEncoding列挙型- サポートされているバーコード形式
アプリケーションでプロフェッショナルなバーコードを生成する準備はできましたか?
IronBarcodeは、プロフェッショナルなアプリケーションに必要な柔軟性を提供しつつ、バーコード生成を簡単にします。 今すぐIronBarcodeをダウンロードして数分でバーコードの生成を開始しましょう。
ライセンスオプションをご確認いただくか、無料の試用キーをリクエストして、IronBarcodeを本番環境でテストしてください。 適切なライセンスの選択に困っていませんか? ライセンス オプションを確認するか、無料トライアル キーをリクエストして、実稼働環境で IronBarcode をテストしてください。
よくある質問
C#でバーコード画像をどのように作成できますか?
C#でバーコード画像を作成するには、IronBarcodeのBarcodeWriter.CreateBarcode()メソッドを使用できます。これにより、データとバーコード形式を指定し、SaveAsPng()などのメソッドを使用してPNGやJPEGの形式で画像を保存できます。
IronBarcodeを.NETプロジェクトにインストールする手順は何ですか?
Visual StudioでNuGetパッケージマネージャーを使用して.NETプロジェクトにIronBarcodeをインストールできます。または、IronBarcodeのウェブサイトからDLLをダウンロードしてプロジェクトリファレンスに追加することもできます。
C#でバーコードをPDFとしてエクスポートするにはどうすれば良いですか?
IronBarcodeを使用すると、GeneratedBarcodeクラスのSaveAsPdf()メソッドを使用してバーコードをPDFとしてエクスポートできます。これはPDF形式でバーコードを保存する簡単な方法を提供します。
C#でバーコードに利用可能なカスタマイズオプションは何ですか?
IronBarcodeは、ChangeBarCodeColor()でバーコードの色を変更したり、AddAnnotationTextAboveBarcode()でテキスト注釈を追加したり、SetMargins()でマージンを設定したりと、幅広いカスタマイズオプションを提供します。
1行のコードでバーコードを迅速に作成しスタイルを設定するにはどうすれば良いですか?
IronBarcodeのフルーエントAPIを使用して、メソッドチェーンを使用した1行のコードでバーコードを作成しスタイルを設定できます: BarcodeWriter.CreateBarcode(data, encoding).ResizeTo(300, 200).SetMargins(10).SaveAsPng(path)。
変更後にバーコードがスキャン可能であることをどうやって確保しますか?
スタイリングやサイズ変更後にバーコードのスキャン可能性を確認するには、Verify()メソッドをGeneratedBarcodeオブジェクトで使用して、その機械読取り可能性をチェックします。
C#でロゴ付きのQRコードを生成することはできますか?
はい、IronBarcodeは、ロゴの挿入とエラーレベルの向上を可能にするQRCodeWriterクラスを使用して埋め込みロゴ付きのQRコード生成をサポートしています。
C#で複数のバーコードを効率的に生成するプロセスはどうなっていますか?
IronBarcodeを使用してC#で複数のバーコードを効率的に生成できます。これはバッチ処理をサポートしており、ループや並列処理を使用して大量のバーコード生成を処理することが可能です。
C#でバーコードをエクスポートするために使用できるファイル形式は何ですか?
IronBarcodeは、PNG、JPEG、GIF、TIFF、BMP、PDF、HTMLなどの様々な形式でのバーコードエクスポートをサポートし、さまざまなアプリケーションニーズに対応する柔軟性を提供します。
C#でバーコードの下に人間が読めるテキストを追加するにはどうすればよいですか?
C#でバーコードの下に人間が読めるテキストを追加するには、AddBarcodeValueTextBelowBarcode()メソッドを使用して、エンコードされた値をバーコード画像の下にテキスト形式で自動的に表示します。

