LEADTOOLS Barcode (Leadtools.Barcode assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
CalculateBarcodeSize Method
See Also 
Leadtools.Barcode Namespace > BarcodeEngine Class : CalculateBarcodeSize Method



dpiX
The X-axis (along width) resolution of the RasterImage of the barcode being written.
dpiY
The Y-axis (along height) resolution of the RasterImage of the barcode being written.
data
BarcodeData class that contains the barcode information to be written on the image.
codeColor
BarcodeColor class that contains the color information to be written on the image.
flags
Flags that indicate the method behavior. Values can be combined when appropriate, by using a bitwise OR (|). Pass BarcodeWriteFlags.None to use the default values, based on the type of barcode that has been written.
code1d
Barcode1d class that contains the information about linear barcodes.
codePdf
BarcodeWritePdf class that contains the information about PDF417 and MicroPDF417 barcodes.
codeDatamatrix
BarcodeWriteDatamatrix class that contains the information about Data Matrix barcodes.
codeQr
BarcodeWriteQr class that contains the information about QR barcodes.
dpiX
The X-axis (along width) resolution of the RasterImage of the barcode being written.
dpiY
The Y-axis (along height) resolution of the RasterImage of the barcode being written.
data
BarcodeData class that contains the barcode information to be written on the image.
codeColor
BarcodeColor class that contains the color information to be written on the image.
flags
Flags that indicate the method behavior. Values can be combined when appropriate, by using a bitwise OR (|). Pass BarcodeWriteFlags.None to use the default values, based on the type of barcode that has been written.
code1d
Barcode1d class that contains the information about linear barcodes.
codePdf
BarcodeWritePdf class that contains the information about PDF417 and MicroPDF417 barcodes.
codeDatamatrix
BarcodeWriteDatamatrix class that contains the information about Data Matrix barcodes.
codeQr
BarcodeWriteQr class that contains the information about QR barcodes.
Calculates the barcode size that is going to be written.

Syntax

Visual Basic (Declaration) 
Public Function CalculateBarcodeSize( _
   ByVal dpiX As Integer, _
   ByVal dpiY As Integer, _
   ByVal data As BarcodeData, _
   ByVal codeColor As BarcodeColor, _
   ByVal flags As BarcodeWriteFlags, _
   ByVal code1d As Barcode1d, _
   ByVal codePdf As BarcodeWritePdf, _
   ByVal codeDatamatrix As BarcodeWriteDatamatrix, _
   ByVal codeQr As BarcodeWriteQr _
) As LeadRect
Visual Basic (Usage)Copy Code
Dim instance As BarcodeEngine
Dim dpiX As Integer
Dim dpiY As Integer
Dim data As BarcodeData
Dim codeColor As BarcodeColor
Dim flags As BarcodeWriteFlags
Dim code1d As Barcode1d
Dim codePdf As BarcodeWritePdf
Dim codeDatamatrix As BarcodeWriteDatamatrix
Dim codeQr As BarcodeWriteQr
Dim value As LeadRect
 
value = instance.CalculateBarcodeSize(dpiX, dpiY, data, codeColor, flags, code1d, codePdf, codeDatamatrix, codeQr)
C++/CLI 
public:
LeadRect CalculateBarcodeSize( 
   int dpiX,
   int dpiY,
   BarcodeData^ data,
   BarcodeColor^ codeColor,
   BarcodeWriteFlags flags,
   Barcode1d^ code1d,
   BarcodeWritePdf^ codePdf,
   BarcodeWriteDatamatrix^ codeDatamatrix,
   BarcodeWriteQr^ codeQr
) 

Parameters

dpiX
The X-axis (along width) resolution of the RasterImage of the barcode being written.
dpiY
The Y-axis (along height) resolution of the RasterImage of the barcode being written.
data
BarcodeData class that contains the barcode information to be written on the image.
codeColor
BarcodeColor class that contains the color information to be written on the image.
flags
Flags that indicate the method behavior. Values can be combined when appropriate, by using a bitwise OR (|). Pass BarcodeWriteFlags.None to use the default values, based on the type of barcode that has been written.
code1d
Barcode1d class that contains the information about linear barcodes.
codePdf
BarcodeWritePdf class that contains the information about PDF417 and MicroPDF417 barcodes.
codeDatamatrix
BarcodeWriteDatamatrix class that contains the information about Data Matrix barcodes.
codeQr
BarcodeWriteQr class that contains the information about QR barcodes.

Return Value

LeadRect with the barcode size before writing the barcode over the image.

Example

Visual BasicCopy Code
Public Sub WriteExample()
      ' Load an image
      Dim codecs As RasterCodecs = New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif"))

      Dim barEngine As BarcodeEngine

      Try
         ' Unlock barcode support.
         ' Note that this is a sample key, which will not work in your toolkit
         RasterSupport.Unlock(RasterSupportType.BarcodesDataMatrixWrite, "TestKey")

         ' Initialize barcodes
         barEngine = New BarcodeEngine()

         Dim data As BarcodeData = New BarcodeData()
         Dim rc As LeadRect = New LeadRect(100, 100, 0, 0)
         data.Unit = BarcodeUnit.ScanlinesPerPixels
         data.Location = rc
         data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault

         Dim barcodeText As String()
         barcodeText = New String(0) {}
         barcodeText(0) = "Data Matrix Default Size"
         data.Data = BarcodeData.ConvertFromStringArray(barcodeText)

         Dim barColor As BarcodeColor = New BarcodeColor()
         barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black)
         barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White)

         Dim bar1d As Barcode1d = New Barcode1d()
         Dim barPDF As BarcodeWritePdf = New BarcodeWritePdf()
         Dim barDM As BarcodeWriteDatamatrix = New BarcodeWriteDatamatrix()

         barDM.Justify = BarcodeJustifyFlags.Right
         barDM.FileIdHigh = 0
         barDM.FileIdLow = 0
         barDM.GroupNumber = 0
         barDM.GroupTotal = 0
         barDM.XModule = 0

         Dim barQR As BarcodeWriteQr = New BarcodeWriteQr()
         barEngine.Write(image, data, barColor, BarcodeWriteFlags.UseColors Or BarcodeWriteFlags.Transparent Or BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty)
      Catch ex As BarcodeException
         Console.WriteLine(ex.Message)
      End Try

   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void WriteExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;
      string fileName = Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif");
      RasterImage image = codecs.Load(fileName);

      BarcodeEngine barEngine;

      try
      {
         // Unlock barcode support.
         // Note that this is a sample key, which will not work in your toolkit
         RasterSupport.Unlock(RasterSupportType.BarcodesDataMatrixWrite, "TestKey");

         // Initialize barcodes
         barEngine = new BarcodeEngine();

         BarcodeData data = new BarcodeData();

         LeadRect rc = new LeadRect(100, 100, 0, 0);
         data.Unit = BarcodeUnit.ScanlinesPerPixels;
         data.Location = rc;
         data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault;

         string[] barcodeText;
         barcodeText = new string[1];
         barcodeText[0] = "Data Matrix Default Size";
         data.Data = BarcodeData.ConvertFromStringArray(barcodeText);

         BarcodeColor barColor = new BarcodeColor();
         barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black);
         barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White);
         Barcode1d bar1d = new Barcode1d();
         BarcodeWritePdf barPDF = new BarcodeWritePdf();
         BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix();

         barDM.Justify = BarcodeJustifyFlags.Right;
         barDM.FileIdHigh = 0;
         barDM.FileIdLow = 0;
         barDM.GroupNumber = 0;
         barDM.GroupTotal = 0;
         barDM.XModule = 0;

         BarcodeWriteQr barQR = new BarcodeWriteQr();

         barEngine.Write(image, data, barColor, BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty);
      }
      catch (BarcodeException ex)
      {
         Console.WriteLine(ex.Message);
      }

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void WriteExample(RasterImage image)
{
   BarcodeEngine barEngine;
   try
   {
      // Unlock barcode support.
      // Note that this is a sample key, which will not work in your toolkit
      RasterSupport.Unlock(RasterSupportType.BarcodesDataMatrixWrite, "TestKey");

      // Initialize barcodes
      barEngine = new BarcodeEngine();

      BarcodeData data = new BarcodeData();

      LeadRect rc = new LeadRect(100, 100, 0, 0);
      data.Unit = BarcodeUnit.ScanlinesPerPixels;
      data.Location = rc;
      data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault;

      string[] barcodeText;
      barcodeText = new string[1];
      barcodeText[0] = "Data Matrix Default Size";
      data.Data = BarcodeData.ConvertFromStringArray(barcodeText);

      BarcodeColor barColor = new BarcodeColor();
      barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black);
      barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White);
      Barcode1d bar1d = new Barcode1d();
      BarcodeWritePdf barPDF = new BarcodeWritePdf();
      BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix();

      barDM.Justify = BarcodeJustifyFlags.Right;
      barDM.FileIdHigh = 0;
      barDM.FileIdLow = 0;
      barDM.GroupNumber = 0;
      barDM.GroupTotal = 0;
      barDM.XModule = 0;

      BarcodeWriteQr barQR = new BarcodeWriteQr();

      barEngine.Write(image, data, barColor, BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty);
   }
   catch (BarcodeException ex)
   {
      Console.WriteLine(ex.Message);
   }

}
SilverlightVBCopy Code
Public Sub WriteExample(ByVal image As RasterImage)
  Dim barEngine As BarcodeEngine
  Try
    ' Unlock barcode support.
    ' Note that this is a sample key, which will not work in your toolkit
    RasterSupport.Unlock(RasterSupportType.BarcodesDataMatrixWrite, "TestKey")

    ' Initialize barcodes
    barEngine = New BarcodeEngine()

    Dim data As BarcodeData = New BarcodeData()

    Dim rc As LeadRect = New LeadRect(100, 100, 0, 0)
    data.Unit = BarcodeUnit.ScanlinesPerPixels
    data.Location = rc
    data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault

    Dim barcodeText As String()
    barcodeText = New String(0){}
    barcodeText(0) = "Data Matrix Default Size"
    data.Data = BarcodeData.ConvertFromStringArray(barcodeText)

    Dim barColor As BarcodeColor = New BarcodeColor()
    barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black)
    barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White)
    Dim bar1d As Barcode1d = New Barcode1d()
    Dim barPDF As BarcodeWritePdf = New BarcodeWritePdf()
    Dim barDM As BarcodeWriteDatamatrix = New BarcodeWriteDatamatrix()

    barDM.Justify = BarcodeJustifyFlags.Right
    barDM.FileIdHigh = 0
    barDM.FileIdLow = 0
    barDM.GroupNumber = 0
    barDM.GroupTotal = 0
    barDM.XModule = 0

    Dim barQR As BarcodeWriteQr = New BarcodeWriteQr()

    barEngine.Write(image, data, barColor, BarcodeWriteFlags.UseColors Or BarcodeWriteFlags.Transparent Or BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty)
  Catch ex As BarcodeException
    Console.WriteLine(ex.Message)
  End Try

End Sub

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features