How to Add Margins to Barcodes

This article was translated from English: Does it need improvement?
Translated
View the article in English

For a barcode to be reliable, it is not just about the bars and spaces. The blank area surrounding the code, known as the "quiet zone" or margin, is just as critical. This quiet zone enables a scanner to distinguish the barcode from other elements on a label, such as text or graphics.

Without a sufficient margin, scans can fail or, worse, return incorrect data. This is particularly important in logistics and retail, where failed scans can result in significant time and financial losses.

IronBarcode provides straightforward methods for configuring these margins, ensuring your barcodes scan accurately every time. In this how-to, we'll explore the methods IronBarcode offers for setting barcode margins.

Get started with IronBarcode

今日あなたのプロジェクトでIronBarcodeを無料トライアルで使用開始。

最初のステップ:
green arrow pointer



Set Margins on All Sides

The simplest and most direct way to ensure a proper quiet zone is by using the SetMargins method. This method accepts a single integer representing the number of pixels to add as a blank border to all four sides of the barcode.

In this example, we will create a barcode, set the margins to 100 pixels, and then save the result using SaveAsPng.

:path=/static-assets/barcode/content-code-examples/how-to/setting-margin-barcode.cs
using IronBarCode;

// Create a QR code
GeneratedBarcode qrcode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com/csharp/barcode",
    BarcodeWriterEncoding.QRCode
);

// Set consistent margins around the QR code
qrcode.SetMargins(100);
// Save the QR code as a PNG image
qrcode.SaveAsPng("QRCode.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

barcode with margins

As you can see in the output, a uniform square margin of 100 pixels has been applied around the barcode.

Set Margins on Each Side

In addition to applying a uniform margin, IronBarcode allows you to specify individual margins for each side using an overload of the SetMargins method. This overload accepts four integer parameters representing the top, right, bottom, and left margins, respectively.

In the following example, we define specific margins: 10 pixels for the top and bottom, and 5 pixels for the left and right.

:path=/static-assets/barcode/content-code-examples/how-to/setting-multiple-margin.cs
using IronBarCode;

// Create a QR code
GeneratedBarcode qrcode = BarcodeWriter.CreateBarcode(
    "https://ironsoftware.com/csharp/barcode",
    BarcodeWriterEncoding.QRCode
);

// Set the QR code dimensions 10 pixel on top and bottom, 5 pixels on left and right
qrcode.SetMargins(10, 5, 10, 5);


// Save the QR code as a PNG file
qrcode.SaveAsPng("QRCodeValue.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Individuals margin barcode

よくある質問

バーコードのクワイエットゾーンとは何ですか?

クワイエットゾーン、またはマージンとは、バーコードの周囲の空白領域です。スキャナーがバーコードをテキストやグラフィックなどの他の要素と区別するために非常に重要です。

バーコードスキャンにおいて余白が重要なのはなぜですか?

マージンを設けることで、バーコードと他の要素を明確に区別し、スキャンの失敗やデータの誤取得を防ぎます。これは、物流や小売業において、時間と金銭の損失を回避するために特に重要です。

IronBarcode を使用してバーコードの余白を設定するにはどうすればよいですか?

IronBarcode は、「SetMargins」と呼ばれる簡単な方法を提供しており、バーコードに均一な余白または個別の余白を適用して、正確なスキャンを保証できます。

IronBarcode でバーコードの各辺に異なる余白を適用できますか?

はい、IronBarcode では、上、右、下、左の余白の 4 つの整数パラメータを受け入れ、'SetMargins' メソッドのオーバーロードを使用して各辺の個別の余白を指定できます。

IronBarcode を使用してバーコードの余白を設定する利点は何ですか?

IronBarcode はバーコードの余白を設定するプロセスを簡素化し、毎回確実にスキャンが確実に実行されるように適切に設定することを保証します。

IronBarcode を使用してバーコードの余白を設定するにはどうすればよいでしょうか?

まずIronBarcode C#ライブラリをダウンロードし、「CreateBarcode」を使ってバーコードを生成し、「SetMargins」を使って余白を設定します。最後に、「SaveAsPng」を使ってバーコードを画像として保存します。

IronBarcode では、バーコードに均一な余白を適用するためにどのような方法を提供していますか?

IronBarcode は、単一の整数を受け入れてバーコードの 4 辺すべてに均一な余白を適用する「SetMargins」メソッドを提供します。

IronBarcode を使用して余白付きのバーコードを画像として保存することは可能ですか?

はい、必要な余白を設定した後、IronBarcode の「SaveAsPng」機能を使用してバーコードを画像として保存できます。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 1,935,276 | バージョン: 2025.11 ただ今リリースされました