public void WriteBarcode(
RasterImage image,
BarcodeData data,
BarcodeWriteOptions options
)
image
The RasterImage that specifies the image to write the barcode to. Must not be null (Nothing in VB).
data
The barcode data. Must not be null (Nothing in VB).
options
Write options. Could be null (Nothing in VB).
Writes a barcode to an image. The data object must contain the data for the barcode (or one of its derived classes). The following members are used by this method:
BarcodeData.Symbology: Specifies the symbology (or type) of the barcode to write. Must not be set to BarcodeSymbology.Unknown.
The raw data stored in BarcodeData.GetData: Must contain the raw data for the symbology in a format and size supported by the barcode standard.
BarcodeData.Bounds: Must contain barcode location (and optionally, its size). Refer to Writing Barcodes - Bounds and XModule for more information.
If options is null (Nothing in VB), then this method will use the default write options associated with the symbology by calling GetDefaultOptions(data.Symbology). If options is not null (Nothing in VB), then this method will use these write options instead of the default ones. The default will use options stored in this BarcodeWriter and will not be overridden by this method at any time.
Note that this method will not check if the options passed in options are associated with symbology stored in BarcodeData.Symbology. If these two do not match, then the default options are used instead.
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:\LEADTOOLS23\Resources\Images";
}
Programming with LEADTOOLS Barcode
UPC / EAN Barcodes in LEADTOOLS
GS1 DataBar / RSS-14 Barcodes in LEADTOOLS
Code 128 Barcodes in LEADTOOLS
USPS and 4-State Barcodes in LEADTOOLS
MSI Barcodes (Pulse Width Modulated) in LEADTOOLS
Miscellaneous Barcodes in LEADTOOLS
Datamatrix Barcodes in LEADTOOLS
PDF417 and MicroPDF417 Barcodes in LEADTOOLS