How to create TIFF barcodes using C# or VB.NET and Barcode Professional for Windows Forms
Product Barcode Professional for Windows Forms Published 07/28/2006 Updated 07/28/2006
Requirements
Neodynamic Barcode Professional 3.0 for Windows Forms
Microsoft .NET Framework (all versions)
Creating TIFF (Tagged Image File Format) barcodes using C# or VB.NET and Barcode Professional for Windows Forms is a very simple task. In the following lines we'll describe some common scenarios about TIFF barcodes generation.
How to create and save a TIFF barcode image at a given resolution
Use the overloaded Save() method that Barcode Professional for Windows Forms features.
Example: You want to encode the data 1234567890 in Code 128 and then save the barcode image in TIFF format at 300DPI
VB
Private Sub SaveBarcode() 'Create a Barcode Professional object Dim bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings (values measured in inches) bcp.BarHeight = 1.5F bcp.BarWidth = 0.02F 'Resolution Dim dpi As Single = 300.0F 'Save the TIFF barcode image on disk bcp.Save("C:\barcode128.tif", System.Drawing.Imaging.ImageFormat.Tiff, dpi, dpi) End SubC#
private void SaveBarcode() { //Create a Barcode Professional object Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings (values measured in inches) bcp.BarHeight = 1.5f; bcp.BarWidth = 0.02f; //Resolution float dpi = 300.0f; //Save the TIFF barcode image on disk bcp.Save(@"C:\barcode128.tif", System.Drawing.Imaging.ImageFormat.Tiff, dpi, dpi); }How to create and save a Monochrome (Black and White 1 bit per pixel) TIFF barcode image at a given resolution
Based on the previous scenario, just specify the Monochrome property that Barcode Professional for Windows Forms features.
NOTE
Keep in mind that generating monochrome images (Black and White 1 bit per pixel format) is a very expensive task in terms of CPU time as well as memory usage.VB
Private Sub SaveBarcode() 'Create a Barcode Professional object Dim bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings (values measured in inches) bcp.BarHeight = 1.5F bcp.BarWidth = 0.02F 'Monochrome (Black and White 1 bit per pixel) bcp.Monochrome = True 'Resolution Dim dpi As Single = 300.0F 'Save the TIFF barcode image on disk bcp.Save("C:\barcode128_BW1bpp.tif", System.Drawing.Imaging.ImageFormat.Tiff, dpi, dpi) End SubC#
private void SaveBarcode() { //Create a Barcode Professional object Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings (values measured in inches) bcp.BarHeight = 1.5f; bcp.BarWidth = 0.02f; //Monochrome (Black and White 1 bit per pixel) bcp.Monochrome = true; //Resolution float dpi = 300.0f; //Save the TIFF barcode image on disk bcp.Save(@"C:\barcode128_BW1bpp.tif", System.Drawing.Imaging.ImageFormat.Tiff, dpi, dpi); }How to get a binary representation of a TIFF barcode image at a given resolution
Use the overloaded GetBarcodeImage() method that Barcode Professional for Windows Forms features.
Example: You want to encode the data 1234567890 in Code 128 and then get a binary representation of the barcode image in TIFF format at 300DPI
VB
Private Function GetTiffBarcode() As Byte() 'Create a Barcode Professional object Dim bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings bcp.BarHeight = 1.5F bcp.BarWidth = 0.02F 'Resolution Dim dpi As Single = 300.0F 'Get the TIFF barcode image in binary format Return bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Tiff, dpi) End FunctionC#
private byte[] GetTiffBarcode() { //Create a Barcode Professional object Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.5f; bcp.BarWidth = 0.02f; //Resolution float dpi = 300.0f; //Get the TIFF barcode image in binary format return bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Tiff, dpi); }How to get a Base64 representation of a TIFF barcode image at a given resolution
Use the overloaded GetBarcodeImage() method that Barcode Professional for Windows Forms features in conjunction with the .NET Convert class.
Example: Based on the previous example, the following code creates a Base64 string representation of the barcode imageVB
Private Function GetTiffBarcode() As String 'Create a Barcode Professional object Dim bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional() 'Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128 'Set the value to encode bcp.Code = "1234567890" 'Barcode dimensions settings bcp.BarHeight = 1.5F bcp.BarWidth = 0.02F 'Resolution Dim dpi As Single = 300.0F 'Get the TIFF barcode image in binary format Dim buffer() as Byte = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Tiff, dpi) 'Convert to Base64 Return Convert.ToBase64String(buffer) End FunctionC#
private string GetTiffBarcode() { //Create a Barcode Professional object Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional(); //Set the barcode symbology to Code 128 bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128; //Set the value to encode bcp.Code = "1234567890"; //Barcode dimensions settings bcp.BarHeight = 1.5f; bcp.BarWidth = 0.02f; //Resolution float dpi = 300.0f; //Get the TIFF barcode image in binary format byte[] buffer = bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Tiff, dpi); //Convert to Base64 return Convert.ToBase64String(buffer); }
Need help? Contact Support
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.