Aspose.BarCode は、さまざまなプログラミング環境におけるバーコードの生成、認識、操作を簡素化する強力なライブラリです。この記事では、1D バーコーダー Writer コンポーネントを使用することに焦点を当てています. .NET 環境の中で. あなたがバルコドを必要とするアプリケーションを開発しているか、またはこの機能で既存のものを強化しているかどうか、このガイドはあなたの開発環境を設定し、バンコッドを生み出すこと、および最良の実践を通してあなたを導きます.

インストール

バーコードの生成に潜り込む前に、必要なコンポーネントがあなたの .NET プロジェクトにインストールされていることを確認します. Aspose.BarCode を統合する最も簡単な方法は NuGet パッケージマネージャーを介して、図書館とその依存性の無制限の設置を可能にします.

  • オープン ビジュアル スタジオまたは好きな IDE.
  • Solution Explorer のプロジェクトを右クリックして、「NuGet パッケージの管理」を選択します".
  • 検索 Aspose.BarCode パッケージマネージャーに入ってインストールします.

代わりに、パッケージマネージャーコンソールで以下のコマンドを使用できます:

using System;
using System.IO;
using Aspose.BarCode;

namespace BarcodeExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set license for Aspose.BarCode
            SetLicense();

            // Generate a basic barcode and save it to the file system
            GenerateBasicBarcode();

            // Generate a custom barcode with specific settings and save it to the file system
            GenerateCustomBarcode();

            // Generate a barcode using BarcodeWriter approach and save it to the file system
            GenerateUsingBarcodeWriter();
        }

        /// <summary>
        /// Sets the license for Aspose.BarCode.
        /// </summary>
        public static void SetLicense()
        {
            try
            {
                // set metered public and private keys
                Aspose.BarCode.Metered metered = new Aspose.BarCode.Metered();
                // Access the setMeteredKey property and pass the public and private keys as parameters
                metered.SetMeteredKey("*****", "*****");

                Console.WriteLine("License set successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error setting license: {ex.Message}");
            }
        }

        /// <summary>
        /// Generates a basic barcode and saves it to the file system.
        /// </summary>
        public static void GenerateBasicBarcode()
        {
            // Create an instance of BarcodeGenerator and set its properties
            using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample Text"))
            {
                // Save barcode image to file system
                generator.Save("barcode.png", BarCodeImageFormat.Png);
                Console.WriteLine("Basic barcode generated successfully.");
            }
        }

        /// <summary>
        /// Generates a custom barcode with specific settings and saves it to the file system.
        /// </summary>
        public static void GenerateCustomBarcode()
        {
            // Create an instance of BarcodeGenerator
            using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128))
            {
                // Set the barcode data
                generator.CodeText = "Sample Text";

                // Customize symbology settings
                generator.Parameters.SymbologyParameters.Code128.AutoExcludeCodabar = true;

                // Save barcode image to file system with custom format and size
                generator.Save("custom_barcode.png", BarCodeImageFormat.Png, 400, 200);
                Console.WriteLine("Custom barcode generated successfully.");
            }
        }

        /// <summary>
        /// Generates a barcode using the BarcodeWriter approach and saves it to the file system.
        /// </summary>
        public static void GenerateUsingBarcodeWriter()
        {
            // Create an instance of BarcodeGenerator
            using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample Text"))
            {
                // Get barcode image as a stream
                using (MemoryStream ms = new MemoryStream())
                {
                    generator.Save(ms, BarCodeImageFormat.Png);

                    // Write the content of memory stream to file system
                    File.WriteAllBytes("barcode_writer.png", ms.ToArray());
                    Console.WriteLine("Barcode generated using BarcodeWriter approach successfully.");
                }
            }
        }
    }
}

インストール後、あなたは Aspose.BarCode の BarcodeWriter クラスを使用してバーコードを生成し始める準備ができています.

ライセンスを作成する

完全な機能性と商業用途のサポートを確保するためには、ライセンスファイルを設定することが不可欠です このステップは、図書館のすべての機能を解除し、試用版に伴う制限を取り除きます.

  • Asposeのウェブサイトからライセンスキーを取得した後、購入または無料試験にサインアップします.
  • 例を生み出す Metered クラスと呼び出し SetMeteredKey() 手順は、電子メールで受け取ったライセンスキーに渡ります:

バーコード生成

Aspose.BarCode を使用して、バーコードの生成は簡単であり、あなたの要求に基づいて幅広くカスタマイズすることができます:

基本バーコード世代

シンプルなバーコードを作成するには BarcodeGenerator クラスから Aspose.BarCode.Generation 名スペース.

バーコードの調整

Aspose.BarCode はバーコードの幅広いカスタマイズを可能にします. シンボロジーの設定、テキストオプション、および外観の特性を調整することができます.

バーコードクラス

The BarcodeGenerator クラスは Aspose.BarCode でバーコードを生成するための主なツールです.しかし、あなたがバーコーディングの生産とリダリングをよりコントロールする必要がある場合は、使用することを検討してください BarcodeWriter クラス.

ベストプラクティス

あなたの .NET アプリケーションで Aspose.BarCode を使用する際に、これらの最良の実践を検討してください:

  • エラー処理: ライセンスを設定し、バーコードを生成する際には常にミス処理メカニズムが含まれます。これは、すべての問題が早期に捕獲され、迅速に解決できることを保証します.

  • パフォーマンス最適化: 高性能シナリオでは、電話の数を最小限にすることによってバーコードの生成を向上させます Save() 複数のバーコードを同時に生成する必要がある場合、バッチ処理を検討します.

  • セキュリティ: ライセンスファイルが安全に保存され、公的手段でアクセスできないことを保証します.

結論

Aspose.BarCode は、 .NET アプリケーションにおけるバーコードの生成、認識、操作のプロセスを簡素化します. このガイドに従って、最小限の努力でプロジェクトにバーコーディング機能を効率的に統合することができます. 詳細な情報や高度な機能については、公式文書を参照してください https://kb.aspose.net/barcode/1d-barcode-writer/.

Aspose.BarCodeの強力なAPIと幅広いカスタマイズオプションにより、特定の要件を満たす高品質のバーコードを作成できます.

More in this category