Leadtools.Barcode Requires Barcode add-on license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.12
Write Method
See Also  Example
Leadtools.Barcode Namespace > BarcodeEngine Class : Write Method




image
RasterImage referencing the bitmap that holds the image data.
data
BarcodeData class that contains the barcode information to be written over the image.
codeColor
BarcodeColor class that contains the color information to be written over 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 related to linear barcodes.
codePdf
BarcodeWritePdf class that contains the information related to PDF417 and MicroPDF417 barcodes.
codeDatamatrix
BarcodeWriteDatamatrix class that contains the information related to Data Matrix barcodes.
codeQr
BarcodeWriteQr class that contains the information related to QR barcodes.
sizeRectangle
Rectangle to be updated with the barcode size before writing the barcode over the image. If the user passes a Rectangle, then the method will calculate the size of the barcode and will update this parameter with the barcode size. Pass Rectangle.Empty to write the barcode over the image.
Writes linear, PDF417, MicroPDF417, Data Matrix, and QR barcode symbols over the image.

Syntax

Visual Basic (Declaration) 
Public Sub Write( _
   ByVal image As RasterImage, _
   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, _
   ByVal sizeRectangle As Rectangle _
) 
Visual Basic (Usage)Copy Code
Dim instance As BarcodeEngine
Dim image As RasterImage
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 sizeRectangle As Rectangle
 
instance.Write(image, data, codeColor, flags, code1d, codePdf, codeDatamatrix, codeQr, sizeRectangle)
Managed Extensions for C++ 
public: void Write( 
   RasterImage image,
   BarcodeData* data,
   BarcodeColor* codeColor,
   BarcodeWriteFlags flags,
   Barcode1d* code1d,
   BarcodeWritePdf* codePdf,
   BarcodeWriteDatamatrix* codeDatamatrix,
   BarcodeWriteQr* codeQr,
   Rectangle sizeRectangle
) 

Parameters

image
RasterImage referencing the bitmap that holds the image data.
data
BarcodeData class that contains the barcode information to be written over the image.
codeColor
BarcodeColor class that contains the color information to be written over 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 related to linear barcodes.
codePdf
BarcodeWritePdf class that contains the information related to PDF417 and MicroPDF417 barcodes.
codeDatamatrix
BarcodeWriteDatamatrix class that contains the information related to Data Matrix barcodes.
codeQr
BarcodeWriteQr class that contains the information related to QR barcodes.
sizeRectangle
Rectangle to be updated with the barcode size before writing the barcode over the image. If the user passes a Rectangle, then the method will calculate the size of the barcode and will update this parameter with the barcode size. Pass Rectangle.Empty to write the barcode over the image.

Example

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

   Dim image As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\barcode1.tif")

   Dim barEngine As BarcodeEngine

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

      ' Initialize linear barcodes
      BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d)
      barEngine = New BarcodeEngine()

      Dim data As BarcodeData = New BarcodeData()
      Dim rc As Rectangle = New Rectangle(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 = Color.Black
      barColor.SpaceColor = Color.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.InitializationReader Or BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, Rectangle.Empty)
      BarcodeEngine.Shutdown()
   Catch ex As BarcodeException
      MessageBox.Show(ex.Message)
   End Try

   RasterCodecs.Shutdown()
End Sub
C#Copy Code
private void WriteExample() 

   // Load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\barcode1.tif"); 
 
   BarcodeEngine barEngine; 
 
   try 
   { 
      // Unlock linear barcode support. 
      // Note that this is a sample key, which will not work in your toolkit 
      RasterSupport.Unlock(RasterSupportType.Barcodes1D, "TestKey"); 
 
      // Initialize linear barcodes 
      BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d); 
      barEngine = new BarcodeEngine(); 
 
      BarcodeData data = new BarcodeData(); 
      Rectangle rc = new Rectangle(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 = Color.Black; 
      barColor.SpaceColor = Color.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.InitializationReader | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, Rectangle.Empty); 
      BarcodeEngine.Shutdown(); 
   } 
   catch (BarcodeException ex) 
   { 
      MessageBox.Show(ex.Message); 
   } 
 
   RasterCodecs.Shutdown(); 
}

Remarks

This method supports all images currently supported by LEADTOOLS.

You must pass a valid RasterImage to this method. If you do not pass a valid Rasterimage, the method will throw an exception.

The Write method will write the barcode symbol over the image using the rectangle defined by the Location property.

However, if the bitmap has a region, this function will write the barcode using the region boundaries. If the region is non-rectangular, the barcode will be written to the rectangle bounding the region and subsequently clipped to the given region. This might cause the resulting barcode to be unreadable.

If you set the flags parameter to .UseColors, then this method will use the codeColor parameter, otherwise the method will ignore it and use the default colors of black for bars and white for spaces.

Using colors does not apply for 1 bit per pixel images.

The BarcodeWriteFlags.UseColors and BarcodeWriteFlags.Transparent are used with all barcode types.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

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