Writing Barcodes - Bounds and XModule

Show in webframe

Barcodes come in many shapes and forms but all of them have a concept of a "symbol". This could be either a vertical bar in 1D linear barcode or a dot in a 2D barcode. Below are examples of common barcodes:

Example of UPC-A. A typical 1D barcode

Example of QR. A typical 2D barcode

The width of the symbol is called the X Module of a barcode and is usually expressed in a 1/1000 of an inch unit. This value must be of an enough size for software and dedicated barcode readers to correctly read the barcode. A typical X Module value is 0.03 of an inch. In imaging terms, this value is dependent on the resolution of the image, for example for an image with resolution of 300 DPI; this value is 9 pixels and so on. A value of 2 pixels is usually the minimum X Module size readable by software.

Another characteristic of barcodes is the aspect ratio between the width and height. Some barcodes have relaxed rules, such as UPC-A, while others are restrict such as QR which must always have a square shape.

When writing barcodes, the software must ensure that the final result satisfies the conditions mentioned above. Otherwise, the final barcode image will not be readable.

The Leadtools.Barcode.BarcodeWriter object contains the Leadtools.Barcode.BarcodeWriter.WriteBarcode(Leadtools.RasterImage,Leadtools.Barcode.BarcodeData,Leadtools.Barcode.BarcodeWriteOptions) method used to write barcodes to an image. This method accepts an object of type Leadtools.Barcode.BarcodeData which contains the symbology, data and location and size of the barcode. The location and size is specified in the BarcodeData.Bounds property.

For all the code snippet in this use the following:

1D Barcodes

The following properties are discussed in this section:

When writing 1D barcodes, you can set the size of the barcode in two modes:

1D Barcodes Without X Module

In this mode, instruct the barcode writer to calculate the X Module value from a specified width and height. To accomplish that, set the "Use X Module" property value to false, and set the width and height desired in BarcodeData.Bounds.

Example: Write a UPC-A barcode on the image with width and height = 400 by 400 pixels.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(0, 0, 400, 400, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(0, 0, 400, 400, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode size is 400 by 400 pixels.

Note that not all 1D barcode types allow you to specify arbitrary aspect ratio (width and height values), some barcodes standard state that the barcode width and height must have a specific aspect ratio, for example if you change the code above to use POSTNET barcode type, the result will be different.

Example: Write a POSTNET barcode on the image with width and height = 400 by 400 pixels.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.PostNet)
             data.Bounds = New LogicalRectangle(0, 0, 400, 400, LogicalUnit.Pixel)
             Dim writeOptions As PostNetPlanetBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), PostNetPlanetBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.PostNet);
             data.Bounds = new LogicalRectangle(0, 0, 400, 400, LogicalUnit.Pixel);
             PostNetPlanetBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as PostNetPlanetBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode size is 400 by 30 pixels.

Set the height of the barcode bounds to 0 to instruct the engine to calculate the barcode height from the width based on a pre-defined aspect ratio.

Example: Write a UPC-A barcode on the image with width and height = 400 by 0 pixels.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(0, 0, 400, 0, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(0, 0, 400, 0, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode size is 400 by 134 pixels

1D Barcodes all have a default aspect ratio 1/3 except for PatchCode, which has an aspect ratio of 5.

In all the modes above, the engine will calculate the X Module from the width value specified. If the result value is illegal (less than 0.03 of an inch), then an exception of type Leadtools.Barcode.BarcodeException width code set to BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight will be thrown.

Example: Write a UPC-A barcode on the image with width and height that is too small (10 by 10 pixels).

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result:Leadtools.Barcode.BarcodeException with code = BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight will be thrown.

1D Barcodes With X Module

In this mode, use a specific X Module value. To accomplish that, you set the "Use X Module" property value to true.

Example: Write a UPC-A barcode on the image with XModule = 0.03 of an inch.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(0, 0, 0, 0, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Use X Module
             writeOptions.UseXModule = True
             writeOptions.XModule = 30
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(0, 0, 0, 0, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Use X Module
             writeOptions.UseXModule = true;
             writeOptions.XModule = 30;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode width is determined by the size of the data (number of bars and spaces required, text options, etc.). The height is calculated based on the preferred aspect ratio of the symbology.

Specify a width or height (both or set one value and leave the other to 0) when using X Module. In this case, these bounds are used as the maximum width and height of the barcode, if the resulting barcode's width or height is greater than the values specified, then an exception of type Leadtools.Barcode.BarcodeException width set to BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight will be thrown.

Example: Write a UPC-A barcode on the image with XModule = 0.03 of an inch and bounds that is too small.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Use X Module
             writeOptions.UseXModule = True
             writeOptions.XModule = 30
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Use X Module
             writeOptions.UseXModule = true;
             writeOptions.XModule = 30;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result:Leadtools.Barcode.BarcodeException with code = BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight will be thrown.

1D Barcodes Location

The left and top position of BarcodeData.Bounds is used exclusively when writing a 1D barcode.

Example: Write a UPC-A barcode on the image at top left 100, 200 position and size of 400 by 100. All in pixels.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(100, 200, 400, 100, LogicalUnit.Pixel)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(100, 200, 400, 100, LogicalUnit.Pixel);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode at 100, 200 with size 400 by 100 pixels.

The BarcodeData.Bounds property is of type LogicalRectangle. This allows you to specify the location and size and a unit other than pixels.

Example: Write a UPC-A barcode at location 1, 2 inches with size equals to 3 by 1 inches.

[Visual Basic]


             Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA)
             data.Bounds = New LogicalRectangle(1, 2, 3, 1, LogicalUnit.Inch)
             Dim writeOptions As OneDBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), OneDBarcodeWriteOptions)
             ' Make sure X Module is disabled
             writeOptions.UseXModule = False
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             BarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.UPCA);
             data.Bounds = new LogicalRectangle(1, 2, 3, 1, LogicalUnit.Inch);
             OneDBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as OneDBarcodeWriteOptions;
             // Make sure X Module is disabled
             writeOptions.UseXModule = false;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode at 1, 2 inches with size 3 by 1 inches.

2D Barcodes

The following properties are discussed in this section:

All 2D barcodes write operations require an X Module. The width and height of BarcodeData.Bounds is only used as the maximum width and height of the barcode.

Example: Write QR using without specifying width and height.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
             data.Bounds = New LogicalRectangle(0, 0, 0, 0, LogicalUnit.Pixel)
             Dim writeOptions As QRBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), QRBarcodeWriteOptions)
             ' Set X Module
             writeOptions.XModule = 30
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
             data.Bounds = new LogicalRectangle(0, 0, 0, 0, LogicalUnit.Pixel);
             QRBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
             // Set X Module
             writeOptions.XModule = 30;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode with size calculated from XModule (about an inch in this case).

Most 2D Barcodes have a strict width and height aspect ratio. For example, QR barcodes must be square (have equal width and height), so these values are only used as the maximum width and height of the barcode, if the resulting barcode's width or height is greater than the values specified, then an exception of type Leadtools.Barcode.BarcodeException, with width set to BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight, will be thrown

Example: Write a QR barcode on the image with XModule = 0.03 of an inch and bounds that are too small.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
             data.Bounds = New LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel)
             Dim writeOptions As QRBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), QRBarcodeWriteOptions)
             ' Use default XModule, it is 30
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
             data.Bounds = new LogicalRectangle(0, 0, 10, 10, LogicalUnit.Pixel);
             QRBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
             // Use default XModule, it is 30
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result:Leadtools.Barcode.BarcodeException with code = BarcodeExceptionCode.InvalidWidth or BarcodeExceptionCode.InvalidHeight will be thrown.

All 2D Barcodes also support an alignment value that can be used to control where the barcode is written inside the bounds.

Example: Write a QR barcode in the middle of the image.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
             ' Use all the image
             data.Bounds = New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel)
             Dim writeOptions As QRBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), QRBarcodeWriteOptions)
             ' Align the barcode in the middle horizontally and vertically
             writeOptions.HorizontalAlignment = BarcodeAlignment.Center
             writeOptions.VerticalAlignment = BarcodeAlignment.Center
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
             // Use all the image
             data.Bounds = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel);
             QRBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
             // Align the barcode in the middle horizontally and vertically
             writeOptions.HorizontalAlignment = BarcodeAlignment.Center;
             writeOptions.VerticalAlignment = BarcodeAlignment.Center;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode that is centered in the image.

Example: Write a QR barcode at the bottom right corner of the image.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
             ' Use all the image
             data.Bounds = New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel)
             Dim writeOptions As QRBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), QRBarcodeWriteOptions)
             ' Align the barcode in bottom corner
             writeOptions.HorizontalAlignment = BarcodeAlignment.Far
             writeOptions.VerticalAlignment = BarcodeAlignment.Far
             barcodeWriter.WriteBarcode(image, data, writeOptions)
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
             // Use all the image
             data.Bounds = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel);
             QRBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
             // Align the barcode in bottom corner
             writeOptions.HorizontalAlignment = BarcodeAlignment.Far;
             writeOptions.VerticalAlignment = BarcodeAlignment.Far;
             barcodeWriter.WriteBarcode(image, data, writeOptions);
             

Result: Barcode at the bottom right edge of the image.

PDF417 and MicroPDF417 barcodes allow you to set the aspect ratio of the "symbol". This allows you to create barcodes with any horizontal and vertical size. Refer to PDF417BarcodeWriteOptions.XModuleAspectRatio and MicroPDF417BarcodeWriteOptions.XModuleAspectRatio.

Calculating Barcode Size

The Leadtools.Barcode.BarcodeWriter class contains the Leadtools.Barcode.BarcodeWriter.CalculateBarcodeDataBounds(Leadtools.Forms.LogicalRectangle,System.Int32,System.Int32,Leadtools.Barcode.BarcodeData,Leadtools.Barcode.BarcodeWriteOptions) method that allows you to calculate the barcode size based on the options specified.

Example: Calculate the size of QR barcode at X Module 0.03.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
             ' It does not matter what the value of data.Bounds is. It will be changed
             Dim writeOptions As QRBarcodeWriteOptions = DirectCast(barcodeWriter.GetDefaultOptions(data.Symbology), QRBarcodeWriteOptions)
             ' Set X Module
             writeOptions.XModule = 30
             ' Calculate the size in pixels if written to this image
             barcodeWriter.CalculateBarcodeDataBounds(New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalRectangle.Empty), image.XResolution, image.YResolution, data, writeOptions)
             Console.WriteLine("{0} by {1} pixels", data.Bounds.Width, data.Bounds.Height)
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
             // It does not matter what the value of data.Bounds is. It will be changed
             QRBarcodeWriteOptions writeOptions = barcodeWriter.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
             // Set X Module
             writeOptions.XModule = 30;
             // Calculate the size in pixels if written to this image
             barcodeWriter.CalculateBarcodeDataBounds(new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalRectangle.Empty), image.XResolution, image.YResolution, data, writeOptions);
             Console.WriteLine("{0} by {1} pixels", data.Bounds.Width, data.Bounds.Height);
             

Result: For an image at 300 DPI, the result is 261 by 261 pixels.

Calculating barcode size works for all barcodes (1D and 2D) and for all options (With or without X Module).

Note that the barcode size may include a few padding areas around the barcode as defined by the standard.

Example: Create a TIF file for a QR object.

[Visual Basic]


             Dim data As QRBarcodeData = DirectCast(BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR), QRBarcodeData)
            
             ' We will use default options throughout this example
            
             ' Calculate the barcode size in pixels at 300 DPI
             Dim resolution As Integer = 300
             barcodeWriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing)
            
             ' Create a RasterImage object with this size
             Dim boundsPixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution)
            
             Using image As New RasterImage(RasterMemoryFlags.Conventional, boundsPixels.Width, boundsPixels.Height, 1, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)
                ' Set the resolution
                image.XResolution = resolution
                image.YResolution = resolution
            
                ' Fill it with white
                Dim cmd As New Leadtools.ImageProcessing.FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White))
                cmd.Run(image)
            
                ' Write the barcode to the image
               barcodeWriter.WriteBarcode(image, data, Nothing)
            
               ' Save it as TIF
                Using codecs As New RasterCodecs()
                  codecs.Save(image, "C:\Users\Public\Documents\LEADTOOLS Images\MyQR.tif", RasterImageFormat.Tif, 1)
                End Using
             End Using
             

[C#]


             QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
            
             // We will use default options through this example
            
             // Calculate the barcode size in pixels at 300 DPI
             int resolution = 300;
             barcodeWriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null);
            
             // Create a RasterImage object with this size
             LeadRect boundsPixels = data.Bounds.ToRectangle(resolution, resolution);
            
             using(RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, boundsPixels.Width, boundsPixels.Height, 1, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0))
             {
                // Set the resolution
                image.XResolution = resolution;
                image.YResolution = resolution;
            
                // Fill it with white
                new Leadtools.ImageProcessing.FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White)).Run(image);
            
                // Write the barcode to the image
                barcodeWriter.WriteBarcode(image, data, null);
            
                // Save it as TIF
                using(RasterCodecs codecs = new RasterCodecs())
                {
                   codecs.Save(image, @"C:\Users\Public\Documents\LEADTOOLS Images\MyQR.tif", RasterImageFormat.Tif, 1);
                }
             }
             

Result: A TIF image of the QR barcode

If needed, you can re-size the image in the example above to the exact pixel size if needed. For instance, to have a QR barcode that is 300 by 300 pixels, add the following code before saving the image:

[Visual Basic]


             Dim cmd As New SizeCommand(300, 300, RasterSizeFlags.Bicubic)
             cmd.Run(image)
             

[C#]


             SizeCommand cmd = new SizeCommand(300, 300, RasterSizeFlags.Bicubic);
             cmd.Run(image);
             

Note: most barcode standards dictate that a padding area with specific size must exist around the barcode. For example, in QR code , this is equal to one symbol size (X Module). LEADTOOLS will always add this padding when writing or calculating the size of a barcode.

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.