C# での OcrProgress トラッキングの使用方法

How to Customize and Style Barcodes

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

長年にわたり、バーコードの使用はますます一般的になり、データ、ID、またはウェブページのURLを保存するなど、さまざまなアプリケーションで使用されています。 一部のアプリケーションでは、バーコードが製品に表示されるため、バーコードをスタイルするためのオプションの需要が増加しています。 そのため、一部のバーコードタイプ/エンコーディングは、PDF417AztecIntelligentMailMaxiCodeDataMatrix などのような、独自の外観を持つものが登場しました。

加えて、IronBarcodeはユーザーにバーコードのさらなるスタイリングオプションを提供しており、バーコードの色バーコードのサイズ変更背景色 などの側面を含みます。 これは、私たちのオープンソースライブラリであるIronDrawingの助けにより実現されています。

クイックスタート: バーコードの色と背景のカスタマイズ

こちらは、開発者がIronBarcodeを使用してバーコードのバーや背景にカスタムカラーを素早く適用する方法を示す簡単な例です。 連鎖呼び出しを1回行うだけでスタイルバーバーコードを生成するのがどれほど簡単かが分かります。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. Copy and run this code snippet.

    IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128)
        .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue)
        .ChangeBackgroundColor(IronSoftware.Drawing.Color.White)
        .SaveAsImage("styled.png");
  3. Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小限のワークフロー(5ステップ)

  1. C#ライブラリをダウンロードしてバーコードをカスタマイズおよびスタイルします
  2. ResizeToメソッドを使用して、劣化なしでリレンダリングをトリガーします
  3. ResizeToMilメソッドを使用してバーコードの要素をサイズ変更します
  4. バーコードとその背景の色を変更します
  5. バーコードの上と下にバーコード注釈を追加します

バーコードサイズ変更の例

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");
    }
}
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");
    }
}
Imports IronBarCode

Public Class BarcodeResizer
	Public Shared Sub ResizeBarcode(ByVal barcodeText As String, ByVal newWidth As Integer, ByVal newHeight As Integer)
		' Generate a barcode
		BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128).ResizeTo(newWidth, newHeight).SaveAsImage("resized_barcode.png")
	End Sub
End Class
$vbLabelText   $csharpLabel

ResizeTo メソッドはGeneratedBarcodeオブジェクトで呼び出すことができます。 以下は、上記のコードスニペットを実行することで生成されたバーコード画像です。

class="content-img-align-center">
class="center-image-wrapper"> リサイズ前のバーコード
class="content-img-align-center">
class="center-image-wrapper"> リサイズ後のバーコード

ResizeToMilメソッドを使用

IronBarcodeで利用可能なサイズ変更のもう一つの側面はResizeToMilメソッドです。 ResizeToメソッドとは異なり、次のコンポーネントを調整します:

  • バーコード要素: 最も狭いバーコード要素の幅、千分の一インチ(mil)で測定。
  • 高さ: バーコードの高さ、インチで測定(デフォルトは1インチ)。
  • 解像度: dpi(デフォルトは96 DPI)。

このメソッドは1Dバーコードに特に適しています。

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");
    }
}
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");
    }
}
Imports IronBarCode

Public Class BarcodeResizer
	Public Shared Sub ResizeBarcodeToMil(ByVal barcodeText As String, ByVal elementWidthMil As Integer, ByVal heightInches As Integer, Optional ByVal dpi As Integer = 96)
		' Generate a barcode
		BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128).ResizeToMil(elementWidthMil, heightInches, dpi).SaveAsImage("resized_barcode_mil.png")
	End Sub
End Class
$vbLabelText   $csharpLabel

また、このメソッドをGeneratedBarcodeオブジェクトで呼び出すことができます。 以下の画像では、ResizeToMilメソッドを適用した結果が見られます。バーコードの端の余白がなくなり、最も狭い要素とバーコードの高さが、メソッドに与えられたパラメータ値に応じて調整されます。

class="content-img-align-center">
class="center-image-wrapper"> ResizeToMil前のバーコード
class="content-img-align-center">
class="center-image-wrapper"> ResizeToMil後のバーコード

バーコードと背景色の変更

バーコードのスタイリングにおいて最も求められている機能の一つは、バーコードと背景の色を両方変更できる機能です。 IronDrawingのおかげで、IronBarcodeはこの機能を提供しています。 GeneratedBarcodeオブジェクトに対してChangeBarCodeColorおよびChangeBackgroundColorメソッドを使用することで、バーコードとその背景の色を変更できます。 以下はそれを達成するための簡単なコードスニペットです。

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");
    }
}
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");
    }
}
Imports IronBarCode
Imports IronSoftware.Drawing ' Required for color manipulation

Public Class BarcodeColorChanger
	Public Shared Sub ChangeBarcodeColors(ByVal barcodeText As String, ByVal barcodeColor As Color, ByVal 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
End Class
$vbLabelText   $csharpLabel
class="content-img-align-center">
class="center-image-wrapper"> カラー付きバーコード

バーコード注釈追加の例

IronBarcodeはバーコード注釈の追加とスタイリングのオプションも提供しています。 注釈のスタイリングは、IronDrawingの機能を利用して、注釈の色とフォントを編集することを含みます。

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, float 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");
    }
}
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, float 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");
    }
}
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 Single)
		' 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
End Class
$vbLabelText   $csharpLabel
class="content-img-align-center">
注釈付きカラーバーコード

前のコードスニペットを拡張すると、バーコードの上部と下部に注釈のフォントとして2つのIronSoftware.Drawing.Fontオブジェクトをインスタンス化します。 フォントファミリーのみがフォントをインスタンス化するのに必要です。

  • AddAnnotationTextAboveBarcode: バーコードの上にカスタム注釈テキストを追加します。
  • AddBarcodeValueTextBelowBarcode: バーコードの値をバーコードの下に追加します。

これら2つのメソッドは、IronSoftware.Drawing.Fontオブジェクト、IronSoftware.Drawing.Colorオブジェクト、およびバーコードとテキスト間の間隔の量を同じパラメータとして受け取ります。 さらに、AddAnnotationTextAboveBarcodeメソッドは、注釈テキスト用の文字列を必要とし、バーコードの上にカスタムテキストを追加します。

IronBarcodeは、ユーザーに幅広いバーコードのカスタマイズとスタイリングの機会を提供しており、想像力以外の制限はありません。 QRコードのカスタマイズについてもっと知りたい場合は、「QRコードにロゴを追加する方法」を参照してください。

よくある質問

.NET C# でバーコードの色を変更するにはどうすればよいですか?

IronBarcode の ChangeBarCodeColor メソッドを使用して .NET C# でバーコードの色を変更できます。これにより、デザインのニーズに合わせてバーコードの外観をカスタマイズできます。

.NET C# でバーコードをリサイズするための利用可能なメソッドは何ですか?

IronBarcode には、ピクセル単位でバーコードをリサイズする ResizeTo および 1D バーコードに適した千分の一インチ単位で幅を調整する ResizeToMil などのメソッドがあります。

C# でバーコードにテキスト注釈を追加できますか?

はい、IronBarcode の AddAnnotationTextAboveBarcode および AddBarcodeValueTextBelowBarcode メソッドを使用して、C# でバーコードにテキスト注釈を追加できます。これにより、ラベル付けと情報を強化できます。

リサイズしたバーコードが読み取れなくなった場合はどうすればよいですか?

小さなサイズでリサイズされたバーコードが読み取り不可能になる場合、IronBarcode はそれらの値を無視して、バーコードが機能を維持することを保証します。

.NET C# で高品質のバーコードレンダリングを確保するにはどうすればよいですか?

高品質のバーコードレンダリングは、サイズ調整時に画像品質を保ちながら、IronBarcode のロスレスリサイズメソッド(ResizeTo または ResizeToMil)を使用することで達成できます。

バーコードの色と注釈スタイルをサポートしているライブラリはどれですか?

IronDrawing はオープンソースのライブラリで、色の操作や注釈のスタイリングを支援し、IronBarcode で創造的で個性的なバーコードデザインを可能にします。

C# でバーコード注釈のフォントを変更することは可能ですか?

はい、IronSoftware.Drawing.Font オブジェクトを使用してバーコード注釈のフォントをカスタマイズし、バーコードの上や下のテキストスタイリングに柔軟性を提供できます。

C# でのバーコードカスタマイズのためのライブラリはどこからダウンロードできますか?

バーコードカスタマイズ用の C# ライブラリは、https://www.nuget.org/packages/BarCode/ からダウンロードできます。これにより、IronBarcode を使用してバーコードのカスタマイズが始められます。

.NET C# でバーコードの背景色をカスタマイズするにはどうすればよいですか?

IronBarcode の ChangeBackgroundColor メソッドを使用して .NET C# でバーコードの背景色をカスタマイズできます。これにより、ユニークなデザインとブランディングの機会が提供されます。

リサイズ後にバーコードの読み取れる状態を維持する最良の方法は何ですか?

リサイズ後の読み取り性を維持するには、IronBarcode のリサイズメソッドを使用します。これにより、バーコードの寸法が機能や明瞭性を損なわないようにします。

Hairil Hasyimi Bin Omar
ソフトウェアエンジニア
すべての優れたエンジニアのように、ハイリルは熱心な学習者です。彼はC#、Python、およびJavaの知識を磨いており、その知識を利用してIron Software全体のチームメンバーに価値を追加しています。ハイリルはマレーシアのマラ工科大学からIron Softwareチームに参加し、化学およびプロセス工学の学士号を取得しました。
準備はいいですか?
Nuget ダウンロード 1,935,276 | バージョン: 2025.11 ただ今リリースされました