←Select platform

GetDefaultOptions Method

Summary
Gets the default write options for a specified symbology.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public BarcodeWriteOptions GetDefaultOptions( 
   BarcodeSymbology symbology 
) 
- (LTBarcodeWriteOptions *)defaultOptionsForSymbology:(LTBarcodeSymbology)symbology; 
public BarcodeWriteOptions getDefaultOptions(BarcodeSymbology symbology) 
public: 
BarcodeWriteOptions^ GetDefaultOptions(  
   BarcodeSymbology symbology 
)  
def GetDefaultOptions(self,symbology): 

Parameters

symbology
An BarcodeSymbology enumeration member that specifies the barcode symbology (or type) to get its options.

Return Value

The BarcodeWriteOptions derived object used by this BarcodeWriter as the default write options to use when writing barcodes of the type specified in  symbology.

Remarks

LEADTOOLS provides extra options to use when writing barcodes. These options are used to fine tune the parameters or provide extra pre-known information that is specific to certain types of barcodes. The base abstract class for the options is BarcodeWriteOptions. LEADTOOLS provides derived classes for each symbology (or group of symbologies). Refer to BarcodeWriteOptions for more information.

The BarcodeWriter class contains default options for each barcode symbology (or group of common symbologies). These options can be retrieved using the GetDefaultOptions method passing the symbology of interest. You can then change the members of the returned BarcodeWriteOptions (or after casting it to the appropriate derived class). These default options will be used by the BarcodeWriter when the user calls the WriteBarcode method with no specific options using null or Nothing for the options parameter.

You can also create an instance of one of the derived BarcodeWriteOptions classes and use it directly in WriteBarcode.

BarcodeSymbology.Unknown is a special type that is used to instruct the engine to read all barcodes. It does not have an associated write options class and should not be used in this method, otherwise, an exception will be thrown.

Example

This example shows how to get the default options used when writing standard linear 1D barcodes (UPC-A, UPC-E, etc) and then changes them before writing a barcode

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeWriter_GetDefaultOptionsExample() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.Writer; 
 
   // Create an image to write the barcodes to 
   int resolution = 300; 
   int width = (int)(resolution * 8.5); 
   int height = (int)(resolution * 11.0); 
   using (RasterImage image = RasterImage.Create(width, height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) 
   { 
      // Write a UPC-A barcode with default options 
      BarcodeData upcaBarcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA); 
      upcaBarcode.Bounds = new LeadRect(0, 0, 400, 100); 
      writer.WriteBarcode(image, upcaBarcode, null); 
 
      // Now change the default options to not show the barcode text when writing 
      OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; 
      oneDWriteOptions.TextPosition = BarcodeOutputTextPosition.None; 
 
      // Write the same barcode with new default options 
      upcaBarcode.Bounds = new LeadRect(0, 200, 400, 100); 
      writer.WriteBarcode(image, upcaBarcode, null); 
 
      // Save the image to disk 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Path; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
 
 
public void barcodeWriterGetDefaultOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_IMAGES_DIR, "barcode1.tif"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.getWriter(); 
 
   // Create an image to write the barcodes to 
   int resolution = 300; 
   int width = (int)(resolution * 8.5); 
   int height = (int)(resolution * 11.0); 
   RasterImage image = RasterImage.create(width, height, 1, resolution, RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
       
   // Write a UPC-A barcode with default options 
   BarcodeData upcaBarcode = BarcodeData.createDefaultBarcodeData(BarcodeSymbology.UPC_A); 
   upcaBarcode.setBounds(new LeadRect(0, 0, 400, 100)); 
   writer.writeBarcode(image, upcaBarcode, null); 
 
   // Now change the default options to not show the barcode text when writing 
   OneDBarcodeWriteOptions oneDWriteOptions = (OneDBarcodeWriteOptions) writer.getDefaultOptions(BarcodeSymbology.UPC_A); 
   oneDWriteOptions.setTextPosition(BarcodeOutputTextPosition.NONE); 
 
   // Write the same barcode with new default options 
   upcaBarcode.setBounds(new LeadRect(0, 200, 400, 100)); 
   writer.writeBarcode(image, upcaBarcode, null); 
 
   // Save the image to disk 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.save(image, imageFileName, RasterImageFormat.CCITT_GROUP4, 1); 
   assertTrue("File unsuccessfully created", (new File(imageFileName)).exists()); 
} 
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.