←Select platform

BarcodeWriter Class

Summary
Main class for the LEADTOOLS support for writing barcodes.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public sealed class BarcodeWriter 
@interface LTBarcodeWriter : NSObject 
public class BarcodeWriter 
public ref class BarcodeWriter sealed  
class BarcodeWriter: 
Remarks

The BarcodeWriter class is used to write a barcode to an image. You cannot create an instance of BarcodeWriter directly, instead, you use the instance created for you inside BarcodeEngine and accessed through the BarcodeEngine.Writer property:

vb[VB Snippet] 
Dim engine As New BarcodeEngine() 
Dim writer As BarcodeWriter = engine.Writer 
' Use can use the writer now, for example, write a UPCA barcode to an image: 
Dim data As New BarcodeData(BarcodeSymbology.UPCA,"01234567890") 
data.Bounds = New LeadRect(0, 0, 400, 200) 
writer.WriteBarcode(myImage, data, Nothing) 
C# Snippet
BarcodeEngine engine = new BarcodeEngine(); 
BarcodeWriter writer = engine.Writer; 
// You can use the writer now, for example, write a UPCA barcode to an image: 
BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA,"01234567890"); 
data.Bounds = new LeadRect(0, 0, 400, 200); 
writer.WriteBarcode(myImage, data, null); 

Or you can use the BarcodeWriter directly through the BarcodeEngine.Writer property:

vb[VB Snippet] 
Dim engine As New BarcodeEngine() 
// Use the instance in BarcodeEngine directly, for example, write a UPCA barcode to an image: 
Dim data As New BarcodeData(BarcodeSymbology.UPCA,"01234567890") 
data.Bounds = New LeadRect(0, 0, 400, 200) 
engine.Writer.WriteBarcode(myImage, data, Nothing) 
C# Snippet
BarcodeEngine engine = new BarcodeEngine(); 
// Use the instance in BarcodeEngine directly, for example, write a UPCA barcode to an image: 
BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA,"01234567890"); 
data.Bounds = new LeadRect(0, 0, 400, 200); 
engine.Write.WriteBarcode(myImage, data, null); 
Example

This example creates a barcode for each symbology supported by LEADTOOLS. It will then save the barcodes as TIFF files.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeWriter_Example() 
{ 
   // 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(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:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Barcode Assembly

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