public virtual LeadRect Bounds { get; set; }
@property (nonatomic, assign) LeadRect bounds;
public LeadRect getBounds()
public void setBounds(LeadRect value)
Bounds # get and set (BarcodeData)
A LeadRect object that specifies the barcode location and size on the image. The default value is LeadRect.Empty. The default value is 0,0,0,0
.
The BarcodeReader.ReadBarcode or BarcodeReader.ReadBarcodes methods are used to read one barcode or more from an image. Each of these methods returns an object or an array of objects of type BarcodeData for each barcode found. Inside each object, the value of the Bounds property will be set by the BarcodeReader object to the location and size of the barcode.
For a tutorial, refer to one of the Extract Barcodes Tutorial.
The BarcodeWriter.WriteBarcode method is used to write barcodes to an image. Create an instance of BarcodeData and fill its members before passing it to this method. The Bounds property informs the BarcodeWriter object of the location and size of this new barcode on the image.
Not all sizes can be used when writing a barcode and the value of the width and height of the bounds can have a special meaning. For more information, refer to Writing Barcodes - Bounds and XModule.
For a tutorial, refer to one of the Write Barcodes Tutorial.
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";
}
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 barcodeWriterExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
// Create a directory to store the images we will create
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) {
System.out.printf("Processing %1s%n", symbology);
// 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 saves to " + outFileName, (new File(outFileName)).exists());
System.out.println("All RasterImages were saved to the output File");
}
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.