←Select platform

CreateDefaultBarcodeData Method

Summary
Returns an instance of BarcodeData suitable for writing containing default and valid values for the specified symbology .
Syntax
C#
Objective-C
C++/CLI
Java
Python
public static BarcodeData CreateDefaultBarcodeData( 
   BarcodeSymbology symbology 
) 
+ (nullable LTBarcodeData *)createDefaultBarcodeData:(LTBarcodeSymbology)symbology 
public static BarcodeData createDefaultBarcodeData(BarcodeSymbology symbology) 
public: 
static BarcodeData^ CreateDefaultBarcodeData(  
   BarcodeSymbology symbology 
)  
def CreateDefaultBarcodeData(self,symbology): 

Parameters

symbology
Barcode symbology.

Return Value

An instance of BarcodeData or one of its derived classes filled with default and legal values of the symbology that can be used directly with BarcodeWriter.WriteBarcode.

Remarks

When writing barcodes, you must fill in a member of BarcodeData with legal values for the symbology based on the standard. This method can be used to quickly create a valid BarcodeData instance for the specified symbology and might be helpful for debugging.

The C# Barcode demos use this method to obtain an initial BarcodeData for a symbology.

Note that if the symbology supports derived BarcodeData types, then an instance of the derived class will be returned instead. This includes DatamatrixBarcodeData, MicroPDF417BarcodeData, PDF417BarcodeData and QRBarcodeData for BarcodeSymbology.Datamatrix, BarcodeSymbology.MicroPDF417, BarcodeSymbology.PDF417 and BarcodeSymbology.QR respectively.

The GetBarcodeDataType method returns the Type of the derived class associated with a specified symbology or the BarcodeData type when the symbology does not have a specialized data class.

Example

This example writes all the supported barcodes with LEADTOOLS using their default values.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
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) 
      { 
         // **Symbology**                  | **Return type** 
         // -------------------------------|------------------------ 
         // BarcodeSymbology.Aztec         | AztecBarcodeData 
         // BarcodeSymbology.Datamatrix    | DatamatrixBarcodeData 
         // BarcodeSymbology.Maxi          | MaxiBarcodeData 
         // BarcodeSymbology.MicroPDF417   | MicroPDF417BarcodeData 
         // BarcodeSymbology.MicroQR       | MicroQRBarcodeData 
         // BarcodeSymbology.PDF417        | PDF417BarcodeData 
         // BarcodeSymbology.QR            | QRBarcodeData 
         // Other BarcodeSymbology members | BarcodeData 
         // 
         // Get Data Type  
         var dataType = BarcodeData.GetBarcodeDataType(symbology); 
         Console.WriteLine("Processing {0} | Data Type:  {1}", symbology, dataType.Name); 
 
 
 
         // Create the default data for this symbology 
         BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology); 
 
         // Calculate its size with default options 
         writer.CalculateBarcodeDataBounds(LeadRect.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, 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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.charset.StandardCharsets; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
 
 
public void barcodeDataCreateDefaultBarcodeDataExample() { 
   // Create a directory to store the images we will create 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String outDir = combine(LEAD_VARS_IMAGES_DIR, "MyBarcodes"); 
   File dir = new File(outDir); 
   if (dir.exists()) 
      dir.delete(); 
   dir.mkdirs(); 
   int resolution = 300; 
 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode writer 
   BarcodeWriter writer = engine.getWriter(); 
 
   // 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 = (OneDBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.UPC_A); 
   oneDWriteOptions.setUseXModule(true); 
 
   // All GS1 Databar Stacked 
   GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = (GS1DatabarStackedBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.GS1_DATA_BAR_STACKED)  ; 
   gs1DatabarStackedWriteOptions.setUseXModule(true); 
 
   // Patch Code 
   PatchCodeBarcodeWriteOptions patchCodeWriteOptions = (PatchCodeBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.PATCH_CODE); 
   patchCodeWriteOptions.setUseXModule(true); 
 
   // All PostNet/Planet 
   PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = (PostNetPlanetBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.POST_NET); 
   postNetPlanetWriteOptions.setUseXModule(true); 
 
   // We will use this object to save files 
   RasterCodecs codecs = new RasterCodecs(); 
          
   // Get all the available write symbologies 
   BarcodeSymbology[] symbologies = writer.getAvailableSymbologies(); 
 
   for (BarcodeSymbology symbology : symbologies) 
   { 
      // **Symbology**                  | **Return type** 
      // -------------------------------|------------------------ 
      // BarcodeSymbology.Aztec         | AztecBarcodeData 
      // BarcodeSymbology.Datamatrix    | DatamatrixBarcodeData 
      // BarcodeSymbology.Maxi          | MaxiBarcodeData 
      // BarcodeSymbology.MicroPDF417   | MicroPDF417BarcodeData 
      // BarcodeSymbology.MicroQR       | MicroQRBarcodeData 
      // BarcodeSymbology.PDF417        | PDF417BarcodeData 
      // BarcodeSymbology.QR            | QRBarcodeData 
      // Other BarcodeSymbology members | BarcodeData 
      // 
      // Get Data Type  
      var dataType = BarcodeData.getBarcodeDataType(symbology); 
      System.out.printf("Processing %1s | Data Type:  %2s%n", symbology, dataType.getName()); 
 
      // Create the default data for this symbology 
      BarcodeData data = BarcodeData.createDefaultBarcodeData(symbology); 
 
      // Calculate its size with default options 
      writer.calculateBarcodeDataBounds(LeadRect.getEmpty(), resolution, resolution, data, null); 
                
      // Create an image to write the data to 
      LeadRect pixels = data.getBounds(); 
      RasterImage image = RasterImage.create(pixels.getWidth(), pixels.getHeight(), 1, resolution, RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
                
      // Write the barcode with default options 
      writer.writeBarcode(image, data, null); 
 
      // Save it 
      String outFileName = combine(outDir, symbology + ".tif"); 
      codecs.save(image, outFileName, RasterImageFormat.TIF, 1); 
      assertTrue("File does not exist", new File(outFileName).exists()); 
      System.out.println("Command run and file exported to: " + outFileName);          
   } 
   codecs.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.