LEADTOOLS Barcode (Leadtools.Barcode assembly)
LEAD Technologies, Inc

GetDefaultOptions Method (BarcodeWriter)

Example 







An BarcodeSymbology enumeration member that specifies the barcode symbology (or type) to get its options.
Gets the default write options for a specified symbology. .NET support Silverlight support
Syntax
public BarcodeWriteOptions GetDefaultOptions( 
   BarcodeSymbology symbology
)
'Declaration
 
Public Function GetDefaultOptions( _
   ByVal symbology As BarcodeSymbology _
) As BarcodeWriteOptions
'Usage
 
Dim instance As BarcodeWriter
Dim symbology As BarcodeSymbology
Dim value As BarcodeWriteOptions
 
value = instance.GetDefaultOptions(symbology)
public BarcodeWriteOptions GetDefaultOptions( 
   BarcodeSymbology symbology
)
ObjectiveC Syntax
 function Leadtools.Barcode.BarcodeWriter.GetDefaultOptions( 
   symbology 
)
public:
BarcodeWriteOptions^ GetDefaultOptions( 
   BarcodeSymbology 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
Copy CodeCopy Code  
Public Sub BarcodeWriter_GetDefaultOptionsExample()
      Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif")

      Dim engine As New BarcodeEngine()
      Dim writer As BarcodeWriter = engine.Writer

      ' Create an image to write the barcodes to
      Dim resolution As Integer = 300
      Dim width As Integer = CType(resolution * 8.5, Integer)
      Dim height As Integer = CType(resolution * 11.0, Integer)
      Using image As RasterImage = RasterImage.Create(width, height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
         ' Write a UPC-A barcode with default options
         Dim upcaBarcode As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
         upcaBarcode.Bounds = New LogicalRectangle(0, 0, 400, 100, LogicalUnit.Pixel)
         writer.WriteBarcode(image, upcaBarcode, Nothing)

         ' Now change the default options to not show the barcode text when writing
         Dim oneDWriteOptions As OneDBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)
         oneDWriteOptions.TextPosition = BarcodeOutputTextPosition.None

         ' Write the same barcode with new default options
         upcaBarcode.Bounds = New LogicalRectangle(0, 200, 400, 100, LogicalUnit.Pixel)
         writer.WriteBarcode(image, upcaBarcode, Nothing)

         ' Save the image to disk
         Using codecs As New RasterCodecs()
            codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1)
         End Using
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
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 LogicalRectangle(0, 0, 400, 100, LogicalUnit.Pixel);
         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 LogicalRectangle(0, 200, 400, 100, LogicalUnit.Pixel);
         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:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task BarcodeWriter_GetDefaultOptionsExample()
{
   string imageFileName = @"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, RasterColorHelper.FromKnownColor(RasterKnownColor.White)))
   {
      // Write a UPC-A barcode with default options
      BarcodeData upcaBarcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
      upcaBarcode.Bounds = LeadRectHelper.Create(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 = LeadRectHelper.Create(0, 200, 400, 100);
      writer.WriteBarcode(image, upcaBarcode, null);

      // Save the image to disk
      using(RasterCodecs codecs = new RasterCodecs())
      {
         StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(imageFileName);
         await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.CcittGroup4, 1);
      }
   }
}
public void BarcodeWriter_GetDefaultOptionsExample(RasterImage image, Stream outStream)
{
   BarcodeEngine engine = new BarcodeEngine();
   BarcodeWriter writer = engine.Writer;
   // Create an image to write the barcodes to
   // Write a UPC-A barcode with default options
   BarcodeData upcaBarcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
   upcaBarcode.Bounds = new LogicalRectangle(0, 0, 400, 100, LogicalUnit.Pixel);
   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 LogicalRectangle(0, 200, 400, 100, LogicalUnit.Pixel);
   writer.WriteBarcode(image, upcaBarcode, null);

   // Save the image to disk
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1);
}
Public Sub BarcodeWriter_GetDefaultOptionsExample(ByVal image As RasterImage, ByVal outStream As Stream)
  Dim engine As BarcodeEngine = New BarcodeEngine()
  Dim writer As BarcodeWriter = engine.Writer
  ' Create an image to write the barcodes to
  ' Write a UPC-A barcode with default options
  Dim upcaBarcode As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
  upcaBarcode.Bounds = New LogicalRectangle(0, 0, 400, 100, LogicalUnit.Pixel)
  writer.WriteBarcode(image, upcaBarcode, Nothing)

  ' Now change the default options to not show the barcode text when writing
  Dim oneDWriteOptions As OneDBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)
  oneDWriteOptions.TextPosition = BarcodeOutputTextPosition.None

  ' Write the same barcode with new default options
  upcaBarcode.Bounds = New LogicalRectangle(0, 200, 400, 100, LogicalUnit.Pixel)
  writer.WriteBarcode(image, upcaBarcode, Nothing)

  ' Save the image to disk
  Dim codecs As RasterCodecs = New RasterCodecs()
  codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

BarcodeWriter Class
BarcodeWriter Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features