LEADTOOLSバーコード(Leadtools.Barcodeアセンブリ)

フレームを表示

CreateDefaultBarcodeDataメソッド








バーコード体系。
指定したバーコード体系の有効なデフォルト値を含む、書き込みに適したBarcodeDataのインスタンスを返します。
構文
public static BarcodeData CreateDefaultBarcodeData( 
   BarcodeSymbology symbology
)
'Declaration
 
Public Shared Function CreateDefaultBarcodeData( _
   ByVal symbology As BarcodeSymbology _
) As BarcodeData
'Usage
 
Dim symbology As BarcodeSymbology
Dim value As BarcodeData
 
value = BarcodeData.CreateDefaultBarcodeData(symbology)
public static BarcodeData CreateDefaultBarcodeData( 
   BarcodeSymbology symbology
)
+ (nullable LTBarcodeData *)createDefaultBarcodeData:(LTBarcodeSymbology)symbology
public static BarcodeData createDefaultBarcodeData(BarcodeSymbology symbology)
 function Leadtools.Barcode.BarcodeData.CreateDefaultBarcodeData( 
   symbology 
)
public:
static BarcodeData^ CreateDefaultBarcodeData( 
   BarcodeSymbology symbology
) 

パラメーター

シンボル
バーコード体系。

戻り値

BarcodeWriter.WriteBarcode。で直接使用できる、バーコード体系の有効なデフォルト値が設定されたBarcodeDataまたはそのいずれかの派生クラスのインスタンス。
解説

バーコードを書き込むときは、BarcodeDataのメンバに、バーコード体系の規格に基づく正規の値を設定する必要があります。このメソッドを使用すると、指定したバーコード体系の有効なBarcodeDataインスタンスをすばやく作成できます。これはデバッグに役立ちます。

C#とVBのバーコードデモは、このメソッドを使用してバーコード体系の初期BarcodeDataを取得します。

シンボルが派生BarcodeDataタイプをサポートするならば、派生クラスのインスタンスが代わりに返される点に注意します。これは、それぞれBarcodeSymbology.DatamatrixBarcodeSymbology.MicroPDF417BarcodeSymbology.PDF417BarcodeSymbology.QRのためにDatamatrixBarcodeDataMicroPDF417BarcodeDataPDF417BarcodeDataQRBarcodeDataを含みます。

GetBarcodeDataTypeメソッドは、指定したバーコード体系に関連づけられた派生クラスのを返します。そのバーコード体系が特別なデータクラスを持たない場合は、BarcodeData型を返します。

注意:LEADTOOLS for Windows Runtimeでは、BarcodeReadOptionsIBarcodeReadOptionsに相当し、BarcodeWriteOptionsIBarcodeWriteOptionsに相当します。

サンプル

このサンプルは、デフォルト値を使用してLEADTOOLSですべてのサポートされたバーコードを書き込みます。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

      
Public Sub BarcodeData_CreateDefaultBarcodeDataExample()
   ' Create a directory to store the images we will create
   Dim outDir As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes")
   If Directory.Exists(outDir) Then
      Directory.Delete(outDir, True)
   End If
   Directory.CreateDirectory(outDir)
   Dim resolution As Integer = 300

   ' Create a Barcode engine
   Dim engine As New BarcodeEngine()

   ' Get the Barcode writer
   Dim writer As BarcodeWriter = engine.Writer

   ' All 1D options have the UseXModule set to false by default, we need to set it to true
   ' so we can calculate the default size. We will change the default options so we can
   ' pass null to CalculateBarcodeDataBounds and WriteBarcode below

   ' For all Standard 1D
   Dim oneDWriteOptions As OneDBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)
   oneDWriteOptions.UseXModule = True

   ' All GS1 Databar Stacked
   Dim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions)
   gs1DatabarStackedWriteOptions.UseXModule = True

   ' Patch Code
   Dim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions)
   patchCodeWriteOptions.UseXModule = True

   ' All PostNet/Planet
   Dim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions)
   postNetPlanetWriteOptions.UseXModule = True

   ' We will use this object to save files
   Using codecs As New RasterCodecs()
      ' Get all the available write symbologies
      Dim symbologies() As BarcodeSymbology = writer.GetAvailableSymbologies()
      For Each symbology As BarcodeSymbology In symbologies
         Console.WriteLine("Processing {0}", symbology)

         ' Create the default data for this symbology
         Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology)

         ' Calculate its size with default options
         writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing)

         ' Create an image to write the data to
         Dim pixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution)
         Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
            ' Write the barcode with default options
            writer.WriteBarcode(image, data, Nothing)

            ' Save it
            Dim outFileName As String = Path.Combine(outDir, symbology.ToString() + ".tif")
            codecs.Save(image, outFileName, RasterImageFormat.Tif, 1)
         End Using
      Next
   End Using
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
public void BarcodeData_CreateDefaultBarcodeDataExample()
{
   // Create a directory to store the images we will create
   string outDir = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes");
   if(Directory.Exists(outDir))
   {
      Directory.Delete(outDir, true);
   }
   Directory.CreateDirectory(outDir);
   int resolution = 300;

   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Get the Barcode writer
   BarcodeWriter writer = engine.Writer;

   // All 1D options have the UseXModule set to false by default, we need to set it to true
   // so we can calculate the default size. We will change the default options so we can
   // pass null to CalculateBarcodeDataBounds and WriteBarcode below

   // For all Standard 1D
   OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;
   oneDWriteOptions.UseXModule = true;

   // All GS1 Databar Stacked
   GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions;
   gs1DatabarStackedWriteOptions.UseXModule = true;

   // Patch Code
   PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions;
   patchCodeWriteOptions.UseXModule = true;

   // All PostNet/Planet
   PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions;
   postNetPlanetWriteOptions.UseXModule = true;

   // We will use this object to save files
   using(RasterCodecs codecs = new RasterCodecs())
   {
      // Get all the available write symbologies
      BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies();
      foreach(BarcodeSymbology symbology in symbologies)
      {
         Console.WriteLine("Processing {0}", symbology);

         // Create the default data for this symbology
         BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology);

         // Calculate its size with default options
         writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null);

         // Create an image to write the data to
         LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution);
         using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
         {
            // Write the barcode with default options
            writer.WriteBarcode(image, data, null);

            // Save it
            string outFileName = Path.Combine(outDir, symbology + ".tif");
            codecs.Save(image, outFileName, RasterImageFormat.Tif, 1);
         }
      }
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
public async Task BarcodeData_CreateDefaultBarcodeDataExample()
{
   int resolution = 300;
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Get the Barcode writer
   BarcodeWriter writer = engine.Writer;

   // All 1D options have the UseXModule set to false by default, we need to set it to true
   // so we can calculate the default size. We will change the default options so we can
   // pass null to CalculateBarcodeDataBounds and WriteBarcode below

   // For all Standard 1D
   OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;
   oneDWriteOptions.UseXModule = true;

   // All GS1 Databar Stacked
   GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions;
   gs1DatabarStackedWriteOptions.UseXModule = true;

   // Patch Code
   PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions;
   patchCodeWriteOptions.UseXModule = true;

   // All PostNet/Planet
   PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions;
   postNetPlanetWriteOptions.UseXModule = true;

   // We will use this object to save files
   using(RasterCodecs codecs = new RasterCodecs())
   {
      // Get all the available write symbologies
      BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies();
      foreach(BarcodeSymbology symbology in symbologies)
      {
         Debug.WriteLine("Processing {0}", symbology);

         // Create the default data for this symbology
         BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology);

         // Calculate its size with default options
         writer.CalculateBarcodeDataBounds(LeadRectHelper.Empty, resolution, resolution, data, null);

         // Create an image to write the data to
         LeadRect pixels = data.Bounds;
         using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColorHelper.FromKnownColor(RasterKnownColor.White)))
         {
            // Write the barcode with default options
            writer.WriteBarcode(image, data, null);

            // Save it
            string outFileName = symbology.ToString() + ".tif";
            StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(outFileName);
            await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1);
         }
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;
using Leadtools.Examples;

public void BarcodeData_CreateDefaultBarcodeDataExample()
{
   int resolution = 300;
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Get the Barcode writer
   BarcodeWriter writer = engine.Writer;

   // All 1D options have the UseXModule set to false by default, we need to set it to true
   // so we can calculate the default size. We will change the default options so we can
   // pass null to CalculateBarcodeDataBounds and WriteBarcode below

   // For all Standard 1D
   OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;
   oneDWriteOptions.UseXModule = true;

   // All GS1 Databar Stacked
   GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions;
   gs1DatabarStackedWriteOptions.UseXModule = true;

   // Patch Code
   PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions;
   patchCodeWriteOptions.UseXModule = true;

   // All PostNet/Planet
   PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions;
   postNetPlanetWriteOptions.UseXModule = true;

   // We will use this object to save files
   RasterCodecs codecs = new RasterCodecs();

   // Get all the available write symbologies
   BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies();
   foreach(BarcodeSymbology symbology in symbologies)
   {
      Console.WriteLine("Processing {0}", symbology);

      // Create the default data for this symbology
      BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology);

      // Calculate its size with default options
      writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null);

      // Create an image to write the data to
      LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution);

      using (RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
      {
         // Write the barcode with default options
         writer.WriteBarcode(image, data, null);

         using (SampleImageStream outputStream = new SampleImageStream(symbology + ".tif"))
         {
            // Save it
            codecs.Save(image, outputStream, RasterImageFormat.Tif, 1);
         }
      }
   }
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

Public Sub BarcodeData_CreateDefaultBarcodeDataExample()
  Dim resolution As Integer = 300
  ' Create a Barcode engine
  Dim engine As BarcodeEngine = New BarcodeEngine()

  ' Get the Barcode writer
  Dim writer As BarcodeWriter = engine.Writer

  ' All 1D options have the UseXModule set to false by default, we need to set it to true
  ' so we can calculate the default size. We will change the default options so we can
  ' pass null to CalculateBarcodeDataBounds and WriteBarcode below

  ' For all Standard 1D
  Dim oneDWriteOptions As OneDBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)
  oneDWriteOptions.UseXModule = True

  ' All GS1 Databar Stacked
  Dim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions)
  gs1DatabarStackedWriteOptions.UseXModule = True

  ' Patch Code
  Dim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions)
  patchCodeWriteOptions.UseXModule = True

  ' All PostNet/Planet
  Dim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions)
  postNetPlanetWriteOptions.UseXModule = True

  ' We will use this object to save files
  Dim codecs As RasterCodecs = New RasterCodecs()

  ' Get all the available write symbologies
  Dim symbologies As BarcodeSymbology() = writer.GetAvailableSymbologies()
  For Each symbology As BarcodeSymbology In symbologies
    Console.WriteLine("Processing {0}", symbology)

    ' Create the default data for this symbology
    Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology)

    ' Calculate its size with default options
    writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing)

    ' Create an image to write the data to
    Dim pixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution)

    Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
       ' Write the barcode with default options
       writer.WriteBarcode(image, data, Nothing)

       Using outputStream As SampleImageStream = New SampleImageStream(symbology & ".tif")
         ' Save it
         codecs.Save(image, outputStream, RasterImageFormat.Tif, 1)
       End Using
    End Using
  Next symbology
End Sub
必要条件

ターゲットプラットホーム

参照

参照

BarcodeDataクラス
BarcodeDataメンバ
GetBarcodeDataTypeメソッド
DatamatrixBarcodeDataクラス
MicroPDF417BarcodeDataクラス
PDF417BarcodeDataクラス
QRBarcodeDataクラス

Leadtools.Barcodeは、バーコードモジュールのライセンスと、解除キーが必要です。詳細は、以下を参照してください。LEADTOOLSツールキット機能