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

BarcodeAlignment Enumeration

ExampleExample 







Horizontal or vertical to use when writing barcodes. .NET support WinRT support Silverlight support
Syntax
'Declaration
 
<SerializableAttribute()>
Public Enum BarcodeAlignment 
   Inherits System.Enum
   Implements System.IComparableSystem.IConvertibleSystem.IFormattable 
'Usage
 
Dim instance As BarcodeAlignment
ObjectiveC Syntax
Java Syntax
Leadtools.Barcode.BarcodeAlignment = function() { };
Leadtools.Barcode.BarcodeAlignment.prototype = {
LeadtoolsMemberMarker(replace me) };
[SerializableAttribute()]
public enum class BarcodeAlignment : public System.Enum, System.IComparableSystem.IConvertibleSystem.IFormattable  
Members
MemberDescription
Center

Aligns the barcode to the center BarcodeData.Bounds. This is horizontal center (LogicalRectangle.Left + (LogicalRectangle.Width - "barcodeWidth") / 2) when this is a horizontal alignment or the vertical center (LogicalRectangle.Top + (LogicalRectangle.Height - "barcodeHeight") / 2) when this is a vertical alignment.

Far

Aligns the barcode to the far edge of BarcodeData.Bounds. This is the left edge (LogicalRectangle.Right - "barcodeWidth") if this is a horizontal alignment or the top edge (LogicalRectangle.Bottom - "barcodeHeight") if this is a vertical alignment.

Near

Aligns the barcode to the near edge of BarcodeData.Bounds. This is the left edge (LogicalRectangle.Left) when this is a horizontal alignment or the top edge (LogicalRectangle.Top) when this is a vertical alignment.

The barcode actual width or height is not used.

Remarks

When writing barcodes, the BarcodeWriter object may not use all the area defined by the output rectangle (BarcodeData.Bounds) since 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.

In cases where not all of the bounds is used, an alignment value can set to determine whether the result barcode is left, top, right, bottom or center aligned to the rectangle. For these, you can use the BarcodeAlignment enumeration to control how the barcode is written.

Alignment is only supported by 2D symbologies (Datamatrix, MicroPDF417, PDF417 and QR). BarcodeAlignment is used as the type for the following properties:

Note that the default values for all these properties is BarcodeAlignment.Near.

Example
Copy CodeCopy Code  
Public Sub BarcodeAlignment_Example()
      Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif")

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

      ' Create the QR barcode
      Dim barcode As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR)

      ' Create the image (8.5 by 11 inches at 300 DPI)
      Dim resolution As Integer = 300
      Using image As RasterImage = RasterImage.Create(CType(8.5 * resolution, Integer), CType(11.0 * resolution, Integer), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
         ' We will control the position by alignment, so set the barcode bound to be the whole image
         barcode.Bounds = New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel)

         Dim options As QRBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeWriteOptions)

         ' Let the engine determine the size of the barcode using X Module (default behavior)

         ' Use these alignments
         Dim verticalAlignments() As BarcodeAlignment = {BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far}
         Dim horizontalAlignments() As BarcodeAlignment = {BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far}

         For Each verticalAlignment As BarcodeAlignment In verticalAlignments
            For Each horizontalAlignment As BarcodeAlignment In horizontalAlignments
               ' Write the barcode using these alignments
               options.HorizontalAlignment = verticalAlignment
               options.VerticalAlignment = horizontalAlignment
               writer.WriteBarcode(image, barcode, options)
            Next
         Next

         ' The image now have 9 barcodes

         ' Save the image
         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 BarcodeAlignment_Example()
   {
      string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif");

      BarcodeEngine engine = new BarcodeEngine();
      BarcodeWriter writer = engine.Writer;

      // Create the QR barcode
      BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR);

      // Create the image (8.5 by 11 inches at 300 DPI)
      int resolution = 300;
      using(RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
      {
         // We will control the position by alignment, so set the barcode bound to be the whole image
         barcode.Bounds = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel);

         QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions;

         // Let the engine determine the size of the barcode using X Module (default behavior)

         // Use these alignments
         BarcodeAlignment[] verticalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };
         BarcodeAlignment[] horizontalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };

         foreach(BarcodeAlignment verticalAlignment in verticalAlignments)
         {
            foreach(BarcodeAlignment horizontalAlignment in horizontalAlignments)
            {
               // Write the barcode using these alignments
               options.HorizontalAlignment = verticalAlignment;
               options.VerticalAlignment = horizontalAlignment;
               writer.WriteBarcode(image, barcode, options);
            }
         }

         // The image now have 9 barcodes

         // Save the image
         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 BarcodeAlignment_Example()
{
   string imageFileName = @"MyBarcode.tif";
   BarcodeEngine engine = new BarcodeEngine();
   BarcodeWriter writer = engine.Writer;

   // Create the QR barcode
   BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR);

   // Create the image (8.5 by 11 inches at 300 DPI)
   int resolution = 300;
   using(RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColorHelper.FromKnownColor(RasterKnownColor.White)))
   {
      // We will control the position by alignment, so set the barcode bound to be the whole image
      barcode.Bounds = LeadRectHelper.Create(0, 0, image.ImageWidth, image.ImageHeight);

      QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions;

      // Let the engine determine the size of the barcode using X Module (default behavior)

      // Use these alignments
      BarcodeAlignment[] verticalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };
      BarcodeAlignment[] horizontalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };

      foreach(BarcodeAlignment verticalAlignment in verticalAlignments)
      {
         foreach(BarcodeAlignment horizontalAlignment in horizontalAlignments)
         {
            // Write the barcode using these alignments
            options.HorizontalAlignment = verticalAlignment;
            options.VerticalAlignment = horizontalAlignment;
            writer.WriteBarcode(image, barcode, options);
         }
      }

      // The image now have 9 barcodes

      // Save the image
      using(RasterCodecs codecs = new RasterCodecs())
      {
         StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(imageFileName);
         await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.CcittGroup4, 1);
      }
   }
}
public void BarcodeAlignment_Example(RasterImage image, Stream outStream)
{
   BarcodeEngine engine = new BarcodeEngine();
   BarcodeWriter writer = engine.Writer;
   // Create the QR barcode
   BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR);

   // Create the image (8.5 by 11 inches at 300 DPI)
   // We will control the position by alignment, so set the barcode bound to be the whole image
   barcode.Bounds = new LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel);

   QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions;

   // Let the engine determine the size of the barcode using X Module (default behavior)

   // Use these alignments
   BarcodeAlignment[] verticalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };
   BarcodeAlignment[] horizontalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far };

   foreach(BarcodeAlignment verticalAlignment in verticalAlignments)
   {
      foreach(BarcodeAlignment horizontalAlignment in horizontalAlignments)
      {
         // Write the barcode using these alignments
         options.HorizontalAlignment = verticalAlignment;
         options.VerticalAlignment = horizontalAlignment;
         writer.WriteBarcode(image, barcode, options);
      }
   }

   // The image now have 9 barcodes

   // Save the image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.CcittGroup4, 1);
}
Public Sub BarcodeAlignment_Example(ByVal image As RasterImage, ByVal outStream As Stream)
  Dim engine As BarcodeEngine = New BarcodeEngine()
  Dim writer As BarcodeWriter = engine.Writer
  ' Create the QR barcode
  Dim barcode As BarcodeData = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR)

  ' Create the image (8.5 by 11 inches at 300 DPI)
  ' We will control the position by alignment, so set the barcode bound to be the whole image
  barcode.Bounds = New LogicalRectangle(0, 0, image.ImageWidth, image.ImageHeight, LogicalUnit.Pixel)

  Dim options As QRBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeWriteOptions)

  ' Let the engine determine the size of the barcode using X Module (default behavior)

  ' Use these alignments
  Dim verticalAlignments As BarcodeAlignment() = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far }
  Dim horizontalAlignments As BarcodeAlignment() = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far }

  For Each verticalAlignment As BarcodeAlignment In verticalAlignments
    For Each horizontalAlignment As BarcodeAlignment In horizontalAlignments
       ' Write the barcode using these alignments
       options.HorizontalAlignment = verticalAlignment
       options.VerticalAlignment = horizontalAlignment
       writer.WriteBarcode(image, barcode, options)
    Next horizontalAlignment
  Next verticalAlignment

  ' The image now have 9 barcodes

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

System.Object
   System.ValueType
      System.Enum
         Leadtools.Barcode.BarcodeAlignment

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

Leadtools.Barcode Namespace

 

 


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