Back

How to create TIFF barcodes using C# or VB.NET and Barcode Professional for WPF

Technologies used
  • Neodynamic Barcode Professional for WPF
  • Microsoft .NET Framework 3.0 or greater
Creating TIFF (Tagged Image File Format) barcodes using C# or VB.NET and Barcode Professional for WPF 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 BarcodeBuilder class (part of Barcode Professional for WPF package) features.
Example: You want to encode the data 1234567890 in Code 128 Symbology and then save the barcode image in TIFF format at 300DPI
Visual Basic .NET
Private Sub SaveBarcode()
    'Create a BarcodeBuilder object

    Dim bc As New Neodynamic.WPF.BarcodeBuilder()
    'Set the barcode symbology to Code 128

    bc.Symbology = Neodynamic.WPF.Symbology.Code128
    'Set the value to encode

    bc.Code = "1234567890"
    'Barcode dimensions settings

    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch
    bc.BarHeight = 1.5D
    bc.BarWidth = 0.02D
   'Output image settings

    bc.ImageSettings.Dpi = 300
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff
    'Save the TIFF barcode image on disk

    bc.Save("C:\barcode128.tif")
End Sub
Visual C# .NET
private void SaveBarcode()
{
    //Create a BarcodeBuilder object
    Neodynamic.WPF.BarcodeBuilder bc = new Neodynamic.WPF.BarcodeBuilder();
    //Set the barcode symbology to Code 128
    bc.Symbology = Neodynamic.WPF.Symbology.Code128;
    //Set the value to encode
    bc.Code = "1234567890";
    //Barcode dimensions settings
    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch;
    bc.BarHeight = 1.5d;
    bc.BarWidth = 0.02d;
    //Output image settings
    bc.ImageSettings.Dpi = 300;
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff;  
    //Save the TIFF barcode image on disk
    bc.Save(@"C:\barcode128.tif");
}
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 ImageSettings.PixelFormat property to System.Windows.Media.PixelFormats.BlackWhite.
Visual Basic .NET
Private Sub SaveBarcode()
    'Create a BarcodeBuilder object

    Dim bc As New Neodynamic.WPF.BarcodeBuilder()
    'Set the barcode symbology to Code 128

    bc.Symbology = Neodynamic.WPF.Symbology.Code128
    'Set the value to encode

    bc.Code = "1234567890"
    'Barcode dimensions settings

    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch
    bc.BarHeight = 1.5D
    bc.BarWidth = 0.02D
   'Output image settings

    bc.ImageSettings.Dpi = 300
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff
    'Set monochrome

    bc.ImageSettings.PixelFormat = System.Windows.Media.PixelFormats.BlackWhite
    'Save the TIFF barcode image on disk

    bc.Save("C:\barcode128_BW.tif")
End Sub
Visual C# .NET
private void SaveBarcode()
{
    //Create a BarcodeBuilder object
    Neodynamic.WPF.BarcodeBuilder bc = new Neodynamic.WPF.BarcodeBuilder();
    //Set the barcode symbology to Code 128
    bc.Symbology = Neodynamic.WPF.Symbology.Code128;
    //Set the value to encode
    bc.Code = "1234567890";
    //Barcode dimensions settings
    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch;
    bc.BarHeight = 1.5d;
    bc.BarWidth = 0.02d;
    //Output image settings
    bc.ImageSettings.Dpi = 300;
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff;  
    //Set monochrome
    bc.ImageSettings.PixelFormat = System.Windows.Media.PixelFormats.BlackWhite;
    //Save the TIFF barcode image on disk
    bc.Save(@"C:\barcode128_BW.tif");
}
How to create and save a CMYK TIFF barcode image at a given resolution
The CMYK color system is often used in printing inks for paper. This type of color representation is of the form CMYK (C%, M%, Y%, K%), where C, M, Y, and K are the percent values for the cyan, magenta, yellow, and black values of the color.
Based on the previous scenario, just specify the ImageSettings.PixelFormat property to System.Windows.Media.PixelFormats.Cmyk32.
Visual Basic .NET
Private Sub SaveBarcode()
    'Create a BarcodeBuilder object

    Dim bc As New Neodynamic.WPF.BarcodeBuilder()
    'Set the barcode symbology to Code 128

    bc.Symbology = Neodynamic.WPF.Symbology.Code128
    'Set the value to encode

    bc.Code = "1234567890"
    'Barcode dimensions settings

    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch
    bc.BarHeight = 1.5D
    bc.BarWidth = 0.02D
   'Output image settings

    bc.ImageSettings.Dpi = 300
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff
    'Set CMYK

    bc.ImageSettings.PixelFormat = System.Windows.Media.PixelFormats.Cmyk32
    'Save the TIFF barcode image on disk

    bc.Save("C:\barcode128_CMYK.tif")
End Sub
Visual C# .NET
private void SaveBarcode()
{
    //Create a BarcodeBuilder object
    Neodynamic.WPF.BarcodeBuilder bc = new Neodynamic.WPF.BarcodeBuilder();
    //Set the barcode symbology to Code 128
    bc.Symbology = Neodynamic.WPF.Symbology.Code128;
    //Set the value to encode
    bc.Code = "1234567890";
    //Barcode dimensions settings
    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch;
    bc.BarHeight = 1.5d;
    bc.BarWidth = 0.02d;
    //Output image settings
    bc.ImageSettings.Dpi = 300;
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff;  
    //Set CMYK
    bc.ImageSettings.PixelFormat = System.Windows.Media.PixelFormats.Cmyk32;
    //Save the TIFF barcode image on disk
    bc.Save(@"C:\barcode128_CMYK.tif");
}
How to get a binary representation of a TIFF barcode image at a given resolution
Use the GetBarcodeImageBinary() method that BarcodeBuilder class (part of Barcode Professional for WPF package) 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
Visual Basic .NET
Private Function GetTiffBarcode() As Byte()
    'Create a BarcodeBuilder object

    Dim bc As New Neodynamic.WPF.BarcodeBuilder()
    'Set the barcode symbology to Code 128

    bc.Symbology = Neodynamic.WPF.Symbology.Code128
    'Set the value to encode

    bc.Code = "1234567890"
    'Barcode dimensions settings

    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch
    bc.BarHeight = 1.5D
    bc.BarWidth = 0.02D
    'Output image settings

    bc.ImageSettings.Dpi = 300
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff
    'Get the TIFF barcode image in binary format

    Return bc.GetBarcodeImageBinary()            
End Function
Visual C# .NET
private byte[] GetTiffBarcode()
{
    //Create a BarcodeBuilder object
    Neodynamic.WPF.BarcodeBuilder bc = new Neodynamic.WPF.BarcodeBuilder();
    //Set the barcode symbology to Code 128
    bc.Symbology = Neodynamic.WPF.Symbology.Code128;
    //Set the value to encode
    bc.Code = "1234567890";
    //Barcode dimensions settings
    bc.BarcodeUnit = Neodynamic.WPF.BarcodeUnit.Inch;
    bc.BarHeight = 1.5d;
    bc.BarWidth = 0.02d;
    //Output image settings
    bc.ImageSettings.Dpi = 300;
    bc.ImageSettings.ImageFormat = Neodynamic.WPF.ImageFormat.Tiff;  
    //Get the TIFF barcode image in binary format
    return bc.GetBarcodeImageBinary();
}
If you need more information or assistance, please contact our .
 Copyright © 2003 - 2010 Neodynamic S.R.L. All rights reserved.