IronBarcodeを使用して.NETのC#でバーコードをカスタマイズしてスタイルを設定する
IronBarcode では、ChangeBarCodeColor() や ResizeTo() などの簡単なメソッド呼び出しを使用して、バーコードの色を変更したり、サイズを調整したり、注釈を追加したりすることにより、C#で開発者がバーコードをカスタマイズでき、完全なスタイリングコントロールが可能です。
ここ数年、BarCodeの使用はますます一般的になり、データ、ID、WebページのURLの保存など、幅広いアプリケーションで使用されています。 アプリケーションによっては、バーコードが製品に表示されるため、スタイリングオプションの需要が高まっています。 したがって、いくつかのバーコードタイプは、PDF417、Aztec、IntelligentMail、MaxiCode、DataMatrix など、多くのユニークな外観を持つように開発されました。 サポートされているフォーマットの詳細な一覧については、Supported Barcode Formatsのドキュメントをご覧ください。
加えて、IronBarcodeはバーコードの色、バーコードのサイズ変更、背景色のような側面を含む、バーコードのスタイルを変更するオプションをユーザーに提供します。 これは、オープンソースライブラリIronDrawingのアシスタンスによって可能になっています。 これらのスタイリング機能は、IronBarcodeの包括的なバーコード生成機能に基づいています。
クイックスタート: バーコードカラーと背景のカスタマイズここでは、開発者がIronBarcodeを使用してバーコードのバーと背景にカスタムカラーをすばやく適用する方法を示す簡単な例を示します。 たった1回の連鎖呼び出しで、スタイル付きBarCodeを生成することがいかに簡単であるか、おわかりいただけるでしょう。 より高度な例については、C# Barcode Image Generatorチュートリアルをご覧ください。
-
1IronBarcode を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128) .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue) .ChangeBackgroundColor(IronSoftware.Drawing.Color.White) .SaveAsImage("styled.png");IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128) _ .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue) _ .ChangeBackgroundColor(IronSoftware.Drawing.Color.White) _ .SaveAsImage("styled.png")IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128) _ .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue) _ .ChangeBackgroundColor(IronSoftware.Drawing.Color.White) _ .SaveAsImage("styled.png") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronBarcodeを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- C#ライブラリをダウンロードして、バーコードをカスタマイズおよびスタイル設定します
ResizeToメソッドを使用してロスレス再レンダリングをトリガーします- バーコード要素のサイズを変更するには、
ResizeToMilメソッドを使用します。 - バーコードやその背景の色を変更
- バーコードの上下にバーコード注釈を追加
バーコードをリサイズするにはどうすればよいですか?
ResizeToメソッドをいつ使用すればよいですか?
バーコードのサイズ変更は、ユーザーがIronBarcodeで実現できるカスタマイズの一つです。 この機能を使用するには、ResizeToメソッドを呼び出し、バーコードの新しい幅と高さの測定値をピクセル単位(px)で入力してください。 このアクションは、バーコードのロスレス再レンダリングをトリガーします。 この方法では、バーコードの品質を維持しながら寸法を調整できるため、バーコードを特定のレイアウトや印刷サイズに合わせる必要がある場合に最適です。
using IronBarCode;
public class BarcodeResizer
{
public static void ResizeBarcode(string barcodeText, int newWidth, int newHeight)
{
// Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
// Resize the barcode
.ResizeTo(newWidth, newHeight)
// Save the resized barcode
.SaveAsImage("resized_barcode.png");
}
// Example usage with different size requirements
public static void ResizeForDifferentFormats()
{
var barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128);
// Resize for product label
barcode.ResizeTo(200, 50).SaveAsImage("product_label.png");
// Resize for shipping label
barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png");
// Resize for inventory tag
barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png");
}
}using IronBarCode;
public class BarcodeResizer
{
public static void ResizeBarcode(string barcodeText, int newWidth, int newHeight)
{
// Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
// Resize the barcode
.ResizeTo(newWidth, newHeight)
// Save the resized barcode
.SaveAsImage("resized_barcode.png");
}
// Example usage with different size requirements
public static void ResizeForDifferentFormats()
{
var barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128);
// Resize for product label
barcode.ResizeTo(200, 50).SaveAsImage("product_label.png");
// Resize for shipping label
barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png");
// Resize for inventory tag
barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png");
}
}Imports IronBarCode
Public Class BarcodeResizer
Public Shared Sub ResizeBarcode(barcodeText As String, newWidth As Integer, newHeight As Integer)
' Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128) _
.ResizeTo(newWidth, newHeight) _
.SaveAsImage("resized_barcode.png")
End Sub
' Example usage with different size requirements
Public Shared Sub ResizeForDifferentFormats()
Dim barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128)
' Resize for product label
barcode.ResizeTo(200, 50).SaveAsImage("product_label.png")
' Resize for shipping label
barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png")
' Resize for inventory tag
barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png")
End Sub
End ClassImports IronBarCode
Public Class BarcodeResizer
Public Shared Sub ResizeBarcode(barcodeText As String, newWidth As Integer, newHeight As Integer)
' Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128) _
.ResizeTo(newWidth, newHeight) _
.SaveAsImage("resized_barcode.png")
End Sub
' Example usage with different size requirements
Public Shared Sub ResizeForDifferentFormats()
Dim barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128)
' Resize for product label
barcode.ResizeTo(200, 50).SaveAsImage("product_label.png")
' Resize for shipping label
barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png")
' Resize for inventory tag
barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png")
End Sub
End ClassResizeTo メソッドは GeneratedBarcode オブジェクトに対して呼び出されます。 異なる出力フォーマットで作業するときには、Create Barcode as PDFガイドを参照すると良いでしょう。以下には、上記のコードスニペットを実行することで生成されたバーコード画像があります。

サイズ変更前

サイズ変更後
なぜ1DバーコードにResizeToMilメソッドを使用するのですか?
IronBarcodeで利用可能なリサイズのもう一つの側面はResizeToMilメソッドです。 このメソッドはResizeToメソッドとは異なり、次のコンポーネントを調整します:
- バーコード要素: 最も狭いバーコード要素の幅、千分の一インチ(mil)で測定。
- 高さ: バーコードの高さ、インチで測定(デフォルトは1インチ)。
- 解像度: dpi(デフォルトは96 DPI)。
この方法は、特に1D BarCodeに適しており、正確な測定が重要な産業用アプリケーションで一般的に使用されています。 mil測定システムは、異なるスキャナや印刷条件で一貫したBarCodeの読みやすさを保証する業界標準です。
using IronBarCode;
public class BarcodeResizer
{
public static void ResizeBarcodeToMil(string barcodeText, int elementWidthMil, int heightInches, int dpi = 96)
{
// Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
// Resize the barcode to mil
.ResizeToMil(elementWidthMil, heightInches, dpi)
// Save the resized barcode
.SaveAsImage("resized_barcode_mil.png");
}
// Example for different industrial standards
public static void CreateIndustrialBarcodes()
{
// Standard retail barcode (10 mil width, 1 inch height)
BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128)
.ResizeToMil(10, 1, 300)
.SaveAsImage("retail_barcode.png");
// High-density warehouse barcode (5 mil width, 0.5 inch height)
BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128)
.ResizeToMil(5, 0.5f, 600)
.SaveAsImage("warehouse_barcode.png");
// Large shipping barcode (15 mil width, 2 inch height)
BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128)
.ResizeToMil(15, 2, 200)
.SaveAsImage("shipping_barcode.png");
}
}using IronBarCode;
public class BarcodeResizer
{
public static void ResizeBarcodeToMil(string barcodeText, int elementWidthMil, int heightInches, int dpi = 96)
{
// Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
// Resize the barcode to mil
.ResizeToMil(elementWidthMil, heightInches, dpi)
// Save the resized barcode
.SaveAsImage("resized_barcode_mil.png");
}
// Example for different industrial standards
public static void CreateIndustrialBarcodes()
{
// Standard retail barcode (10 mil width, 1 inch height)
BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128)
.ResizeToMil(10, 1, 300)
.SaveAsImage("retail_barcode.png");
// High-density warehouse barcode (5 mil width, 0.5 inch height)
BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128)
.ResizeToMil(5, 0.5f, 600)
.SaveAsImage("warehouse_barcode.png");
// Large shipping barcode (15 mil width, 2 inch height)
BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128)
.ResizeToMil(15, 2, 200)
.SaveAsImage("shipping_barcode.png");
}
}Imports IronBarCode
Public Class BarcodeResizer
Public Shared Sub ResizeBarcodeToMil(barcodeText As String, elementWidthMil As Integer, heightInches As Integer, Optional dpi As Integer = 96)
' Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128) _
.ResizeToMil(elementWidthMil, heightInches, dpi) _
.SaveAsImage("resized_barcode_mil.png")
End Sub
' Example for different industrial standards
Public Shared Sub CreateIndustrialBarcodes()
' Standard retail barcode (10 mil width, 1 inch height)
BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128) _
.ResizeToMil(10, 1, 300) _
.SaveAsImage("retail_barcode.png")
' High-density warehouse barcode (5 mil width, 0.5 inch height)
BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128) _
.ResizeToMil(5, 0.5F, 600) _
.SaveAsImage("warehouse_barcode.png")
' Large shipping barcode (15 mil width, 2 inch height)
BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128) _
.ResizeToMil(15, 2, 200) _
.SaveAsImage("shipping_barcode.png")
End Sub
End ClassImports IronBarCode
Public Class BarcodeResizer
Public Shared Sub ResizeBarcodeToMil(barcodeText As String, elementWidthMil As Integer, heightInches As Integer, Optional dpi As Integer = 96)
' Generate a barcode
BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128) _
.ResizeToMil(elementWidthMil, heightInches, dpi) _
.SaveAsImage("resized_barcode_mil.png")
End Sub
' Example for different industrial standards
Public Shared Sub CreateIndustrialBarcodes()
' Standard retail barcode (10 mil width, 1 inch height)
BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128) _
.ResizeToMil(10, 1, 300) _
.SaveAsImage("retail_barcode.png")
' High-density warehouse barcode (5 mil width, 0.5 inch height)
BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128) _
.ResizeToMil(5, 0.5F, 600) _
.SaveAsImage("warehouse_barcode.png")
' Large shipping barcode (15 mil width, 2 inch height)
BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128) _
.ResizeToMil(15, 2, 200) _
.SaveAsImage("shipping_barcode.png")
End Sub
End ClassこのメソッドもGeneratedBarcodeオブジェクトで呼び出すことができます。 正確なバーコード寸法の設定に関する詳細は、Set Barcodes Marginsガイドをご参照ください。下の画像では、ResizeToMilメソッドを適用した結果を見ることができます: バーコードの端の余白がなくなり、最も狭い要素とバーコードの高さが、メソッドに渡されたパラメータ値に基づいて調整されます。

ResizeToMil の前

ResizeToMil後
バーコードと背景色をどのように変更できますか?
バーコードのスタイリングにおいて最も求められている機能の一つは、バーコードと背景の色を両方変更できる機能です。 IronDrawingのおかげで、IronBarcodeはこの機能を提供しています。 ChangeBarCodeColor メソッドと ChangeBackgroundColor メソッドを GeneratedBarcode オブジェクトに対して使用することにより、ユーザーはバーコードとその背景の色を変更できます。 この機能は、ブランディングを目的とする場合や、特別なイベントや製品ラインのテーマバーコードを作成する場合に特に役立ちます。
using IronBarCode;
using IronSoftware.Drawing; // Required for color manipulation
public class BarcodeColorChanger
{
public static void ChangeBarcodeColors(string barcodeText, Color barcodeColor, Color backgroundColor)
{
// Generate a barcode
var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);
// Change the barcode color
barcode.ChangeBarCodeColor(barcodeColor);
// Change the background color
barcode.ChangeBackgroundColor(backgroundColor);
// Save the colored barcode
barcode.SaveAsImage("colored_barcode.png");
}
// Example: Create branded barcodes with company colors
public static void CreateBrandedBarcodes()
{
// Company brand colors example
var barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128);
// Apply brand colors
barcode.ChangeBarCodeColor(new Color("#1E3A8A")) // Company blue
.ChangeBackgroundColor(new Color("#F3F4F6")) // Light gray background
.SaveAsImage("branded_barcode.png");
// Create seasonal variation
var seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128);
seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen)
.ChangeBackgroundColor(Color.LightYellow)
.SaveAsImage("seasonal_barcode.png");
}
}using IronBarCode;
using IronSoftware.Drawing; // Required for color manipulation
public class BarcodeColorChanger
{
public static void ChangeBarcodeColors(string barcodeText, Color barcodeColor, Color backgroundColor)
{
// Generate a barcode
var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);
// Change the barcode color
barcode.ChangeBarCodeColor(barcodeColor);
// Change the background color
barcode.ChangeBackgroundColor(backgroundColor);
// Save the colored barcode
barcode.SaveAsImage("colored_barcode.png");
}
// Example: Create branded barcodes with company colors
public static void CreateBrandedBarcodes()
{
// Company brand colors example
var barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128);
// Apply brand colors
barcode.ChangeBarCodeColor(new Color("#1E3A8A")) // Company blue
.ChangeBackgroundColor(new Color("#F3F4F6")) // Light gray background
.SaveAsImage("branded_barcode.png");
// Create seasonal variation
var seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128);
seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen)
.ChangeBackgroundColor(Color.LightYellow)
.SaveAsImage("seasonal_barcode.png");
}
}Imports IronBarCode
Imports IronSoftware.Drawing ' Required for color manipulation
Public Class BarcodeColorChanger
Public Shared Sub ChangeBarcodeColors(barcodeText As String, barcodeColor As Color, backgroundColor As Color)
' Generate a barcode
Dim barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
' Change the barcode color
barcode.ChangeBarCodeColor(barcodeColor)
' Change the background color
barcode.ChangeBackgroundColor(backgroundColor)
' Save the colored barcode
barcode.SaveAsImage("colored_barcode.png")
End Sub
' Example: Create branded barcodes with company colors
Public Shared Sub CreateBrandedBarcodes()
' Company brand colors example
Dim barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128)
' Apply brand colors
barcode.ChangeBarCodeColor(New Color("#1E3A8A")) ' Company blue
.ChangeBackgroundColor(New Color("#F3F4F6")) ' Light gray background
.SaveAsImage("branded_barcode.png")
' Create seasonal variation
Dim seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128)
seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen) _
.ChangeBackgroundColor(Color.LightYellow) _
.SaveAsImage("seasonal_barcode.png")
End Sub
End ClassImports IronBarCode
Imports IronSoftware.Drawing ' Required for color manipulation
Public Class BarcodeColorChanger
Public Shared Sub ChangeBarcodeColors(barcodeText As String, barcodeColor As Color, backgroundColor As Color)
' Generate a barcode
Dim barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
' Change the barcode color
barcode.ChangeBarCodeColor(barcodeColor)
' Change the background color
barcode.ChangeBackgroundColor(backgroundColor)
' Save the colored barcode
barcode.SaveAsImage("colored_barcode.png")
End Sub
' Example: Create branded barcodes with company colors
Public Shared Sub CreateBrandedBarcodes()
' Company brand colors example
Dim barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128)
' Apply brand colors
barcode.ChangeBarCodeColor(New Color("#1E3A8A")) ' Company blue
.ChangeBackgroundColor(New Color("#F3F4F6")) ' Light gray background
.SaveAsImage("branded_barcode.png")
' Create seasonal variation
Dim seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128)
seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen) _
.ChangeBackgroundColor(Color.LightYellow) _
.SaveAsImage("seasonal_barcode.png")
End Sub
End Class色付きの BarCode を扱う場合は、バーコードと背景色のコントラストを十分に保ち、読みやすさを確保することが重要です。 QRコードに特化したスタイリングオプションについては、QR Codesのカスタマイズとスタイル設定を参照してください。

バーコードに注釈を追加するにはどうすればよいですか?
IronBarcodeはバーコード注釈の追加とスタイリングのオプションも提供しています。 アノテーションのスタイリングもIronDrawingの機能によってサポートされ、アノテーションの色とフォントを編集することができます。 注釈は、機械読み取り可能な BarCode と並んで、人間が読み取り可能な情報を提供するために不可欠であり、在庫管理、製品ラベリング、および出荷アプリケーションにとって非常に重要です。
using IronBarCode;
using IronSoftware.Drawing; // Required for font and color manipulation
public class BarcodeAnnotator
{
public static void AnnotateBarcode(string barcodeText, string annotationText, Font annotationFont, Color annotationColor, int annotationSpacing)
{
// Generate a barcode
var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);
// Add annotation above the barcode
barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing);
// Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing);
// Save the annotated barcode
barcode.SaveAsImage("annotated_barcode.png");
}
// Example: Create product label with annotations
public static void CreateProductLabel()
{
var productCode = "PRD-12345-XL";
var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);
// Define fonts for different purposes
var titleFont = new Font("Arial", FontStyle.Bold, 14);
var valueFont = new Font("Arial", FontStyle.Regular, 12);
// Add product name above
barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5);
// Add product code below
barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3);
// Apply additional styling
barcode.ResizeTo(250, 80)
.SaveAsImage("product_label_annotated.png");
}
}using IronBarCode;
using IronSoftware.Drawing; // Required for font and color manipulation
public class BarcodeAnnotator
{
public static void AnnotateBarcode(string barcodeText, string annotationText, Font annotationFont, Color annotationColor, int annotationSpacing)
{
// Generate a barcode
var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);
// Add annotation above the barcode
barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing);
// Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing);
// Save the annotated barcode
barcode.SaveAsImage("annotated_barcode.png");
}
// Example: Create product label with annotations
public static void CreateProductLabel()
{
var productCode = "PRD-12345-XL";
var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);
// Define fonts for different purposes
var titleFont = new Font("Arial", FontStyle.Bold, 14);
var valueFont = new Font("Arial", FontStyle.Regular, 12);
// Add product name above
barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5);
// Add product code below
barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3);
// Apply additional styling
barcode.ResizeTo(250, 80)
.SaveAsImage("product_label_annotated.png");
}
}Imports IronBarCode
Imports IronSoftware.Drawing ' Required for font and color manipulation
Public Class BarcodeAnnotator
Public Shared Sub AnnotateBarcode(ByVal barcodeText As String, ByVal annotationText As String, ByVal annotationFont As Font, ByVal annotationColor As Color, ByVal annotationSpacing As Integer)
' Generate a barcode
Dim barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
' Add annotation above the barcode
barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing)
' Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing)
' Save the annotated barcode
barcode.SaveAsImage("annotated_barcode.png")
End Sub
' Example: Create product label with annotations
Public Shared Sub CreateProductLabel()
Dim productCode = "PRD-12345-XL"
Dim barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128)
' Define fonts for different purposes
Dim titleFont = New Font("Arial", FontStyle.Bold, 14)
Dim valueFont = New Font("Arial", FontStyle.Regular, 12)
' Add product name above
barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5)
' Add product code below
barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3)
' Apply additional styling
barcode.ResizeTo(250, 80).SaveAsImage("product_label_annotated.png")
End Sub
End ClassImports IronBarCode
Imports IronSoftware.Drawing ' Required for font and color manipulation
Public Class BarcodeAnnotator
Public Shared Sub AnnotateBarcode(ByVal barcodeText As String, ByVal annotationText As String, ByVal annotationFont As Font, ByVal annotationColor As Color, ByVal annotationSpacing As Integer)
' Generate a barcode
Dim barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
' Add annotation above the barcode
barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing)
' Add barcode value text below the barcode
barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing)
' Save the annotated barcode
barcode.SaveAsImage("annotated_barcode.png")
End Sub
' Example: Create product label with annotations
Public Shared Sub CreateProductLabel()
Dim productCode = "PRD-12345-XL"
Dim barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128)
' Define fonts for different purposes
Dim titleFont = New Font("Arial", FontStyle.Bold, 14)
Dim valueFont = New Font("Arial", FontStyle.Regular, 12)
' Add product name above
barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5)
' Add product code below
barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3)
' Apply additional styling
barcode.ResizeTo(250, 80).SaveAsImage("product_label_annotated.png")
End Sub
End Class
前述のコードスニペットの拡張として、バーコードの上下にアノテーション用のフォントとして機能する2つの新しいIronSoftware.Drawing.Fontオブジェクトをインスタンス化します。 フォントをインスタンス化するために必要なのはフォントファミリーだけですが、サイズやスタイルなどのプロパティを追加で指定することで、より詳細に制御することができます。
AddAnnotationTextAboveBarcode: バーコードの上にカスタムアノテーションテキストを追加します。AddBarcodeValueTextBelowBarcode: バーコードの下にバーコードの値を追加します。
これらの2つのメソッドは同じパラメーターを受け入れます: IronSoftware.Drawing.Font オブジェクト、IronSoftware.Drawing.Color オブジェクト、およびバーコードとテキストの間のスペース量です。 さらに、AddAnnotationTextAboveBarcodeメソッドは、カスタムテキストをバーコードの上に追加するために、アノテーションテキストのための文字列を必要とします。
IronBarcodeはバーコードのスタイリングに幅広いカスタマイズオプションを提供しています。 アノテーションでUnicodeサポートが必要なアプリケーションの場合は、Unicodeバーコードの書き方ガイドをご参照ください。QRコードをカスタマイズする方法については、「QRコードにロゴをカスタマイズして追加する方法」をご覧ください。 スタイル設定されたバーコードを異なる形式にエクスポートする場合は、Create Barcode as HTMLのチュートリアルをご参照ください。
よくある質問
IronBarcodeを使用してバーコードの色をどのようにカスタマイズできますか?
IronBarcodeでは、ChangeBarCodeColor()およびChangeBackgroundColor()メソッドを使ってバーコードの色をカスタマイズできます。これらのメソッドにより、バーコードと背景の色を調整することができ、特にブランドやテーマに合わせたバーコードを作成するのに役立ちます。
IronBarcodeでバーコードをリサイズするにはどのメソッドを使うべきですか?
バーコードをリサイズするには、IronBarcodeが提供するResizeTo()メソッドを使用してください。このメソッドにより、新しい幅と高さの寸法をピクセル単位で指定でき、バーコードの品質を維持しながらロスレスで再レンダリングできます。
いつResizeToMilメソッドが推奨されますか?
ResizeToMilメソッドは、特に正確な測定が必須である工業用途の1Dバーコードに推奨されます。これは、バーコード要素の幅にミル(インチの1000分の1)を使用して、異なるスキャナや条件でも一貫して読み取り可能にします。
IronBarcodeでバーコードに注釈を追加するにはどうすればいいですか?
IronBarcodeでは、AddAnnotationTextAboveBarcodeやAddBarcodeValueTextBelowBarcodeのようなメソッドを使用して注釈を追加するオプションがあります。これにより、カスタムテキストをバーコードの上に、バーコードの値を下に追加でき、製品ラベルや在庫管理に役立ちます。
IronBarcodeでサポートされているバーコード形式にはどのようなものがありますか?
IronBarcodeは、PDF417、Aズテック、インテリジェントメール、マキシコード、データマトリックスなど、多くのバーコード形式をサポートしています。サポートされている形式の完全なリストは、IronBarcodeのウェブサイトのSupported Barcode Formatsドキュメントをご覧ください。
IronBarcodeを使用してカスタムスタイルのQRコードを作成できますか?
はい、IronBarcodeでは、他のバーコードで利用可能なメソッドを使用してQRコードをカスタマイズおよびスタイル設定することができます。色を変更したり、ロゴを追加したりと、QRコードに幅広いスタイリングを施すことが可能です。
IronBarcodeはリサイズ中にバーコードの品質をどのように維持しますか?
IronBarcodeは、ResizeTo()のようなメソッドを使用した際にロスレスな再レンダリングプロセスをトリガーすることで、リサイズ中のバーコードの品質を維持します。これにより、バーコードがリサイズ後も高品質で可読性を保つことが保証されます。
IronBarcodeには高度な色操作のサポートがありますか?
IronBarcodeでは、IronDrawingライブラリとの統合により高度な色操作がサポートされています。これにより、バーコードと背景色の正確なコントロールが可能になり、ブランドやテーマに合わせることができます。
IronBarcodeは製品ラベルの作成にどのように役立ちますか?
IronBarcodeは、注釈の追加、バーコード寸法のカスタマイズ、色の変更による製品のブランド適合を通じて製品ラベルの作成を支援します。AddAnnotationTextAboveBarcodeのようなメソッドにより、ラベルに人間が読み取れる情報を追加することができます。
IronBarcodeでのバーコード注釈にはどのようなフォントオプションがありますか?
バーコード注釈のために、IronBarcodeはIronSoftware.Drawing.Fontを通じてフォントファミリー、サイズ、スタイル、色をカスタマイズするオプションを提供します。これにより、特定の製品やブランドのニーズに合わせた注釈のスタイリングに柔軟性が加わります。