Home > Code > C# > How to Generate & Recognize Barcode using Custom Width inside .NET Apps

How to Generate & Recognize Barcode using Custom Width inside .NET Apps

by sher azam   on Jun 17, 2015   Category: C#   |  Views: 654    |  Points: 25   |  Gold 


This Technical tip explains how .NET developers can generate barcode using custom width support inside their applications using Aspose.BarCode for .NET. Originally, barcodes systematically represented data by varying the widths and spacing’s of parallel lines. Now, you can generate and recognize barcodes with custom widths. The idea is to calculate the widths for all supported properties and generate a barcode that fits in the space left. Barcodes with custom widths support these properties:
• Caption above and below (but not located to the left, center or right).
• Codetext (only at the bottom).
• Margins.
• Supports different graphics unit as usual.
• Limited to 2 lines for each type of text. More would flatten the barcode image.
• If no license has been applied (if you're testing Aspose.BarCode) Aspose wording automatically appears at the top left corner.
• To get a barcode image with no text or margins, turn off those properties.
The following code snippet shows how to generate barcode using custom width support

// Code sample for creating an Image with Exact Barcode Only

//[C# Code Sample]

// Generate the barcode
BarCodeBuilder builder = new BarCodeBuilder();
// Set symbology type
builder.SymbologyType = Symbology.Code128;
// Set the code text
builder.CodeText = "123456";
// Get bitmap with exact barcode only
Bitmap bmp = builder.GetOnlyBarCodeImage();
// Save image on local
bmp.Save("c:\\barcode.png", ImageFormat.Png);

//[VB.NET Code Sample]

' Generate the barcode
Dim builder As New BarCodeBuilder()
' Set symbology type
builder.SymbologyType = Symbology.Code128
' Set the code text
Dim codetext As String = "123456";
builder.CodeText = codetext
' Get bitmap with exact barcode only
Dim bmp As Bitmap = builder.GetOnlyBarCodeImage()
' Save image on local
bmp.Save("c:\\barcode.png")

//Create and Set Size for Whole Picture With Barcode inside

//[C# Code Sample]

// Generate the barcode
BarCodeBuilder builder = new BarCodeBuilder();
// Set symbology type
builder.SymbologyType = Symbology.Pdf417;
// Set the code text
builder.CodeText = "One thing 2 thing";
// Set the code text location
builder.CodeLocation = CodeLocation.None;
// Set graphics unit
builder.GraphicsUnit = GraphicsUnit.Pixel;
// Set margins
builder.Margins.Set(0);
// Get Bitmap with exact barcode only
Bitmap bmp = builder.GetOnlyBarCodeImage();
// Allows to set size for whole picture with barcode inside
Bitmap tt = builder.GetCustomSizeBarCodeImage(new Size(bmp.Width * 5, bmp.Height * 5), false);
// Save image on local
tt.Save(@"c:\ab\v5.2\test20\barcode2.png", ImageFormat.Png);

//[VB.NET Code Sample]

' Generate the barcode
Dim builder As New BarCodeBuilder()
' Set symbology type
builder.SymbologyType = Symbology.Pdf417
' Set the code text
builder.CodeText = "One thing 2 thing"
' Set the code text location
builder.CodeLocation = CodeLocation.None
' Set graphics unit
builder.GraphicsUnit = GraphicsUnit.Pixel
' Set margins
builder.Margins.[Set](0)
' Get Bitmap with exact barcode only
Dim bmp As Bitmap = builder.GetOnlyBarCodeImage()
' Allows to set size for whole picture with barcode inside
Dim tt As Bitmap = builder.GetCustomSizeBarCodeImage(New Size(bmp.Width * 5, bmp.Height * 5), False)
' Save image on local
tt.Save("c:\ab\v5.2\test20\barcode2.png", ImageFormat.Png)



Overview: Aspose.BarCode for .NET

Aspose.BarCode is a .NET component for generation and recognition of Linear and 2D barcodes on all kinds of .NET applications. It supports WPF with 29+ Barcode symbologies like OneCode, QR, Aztec, MSI, EAN128, EAN14, SSCC18, Code128, Code39, Postnet, MarcoPDF417, Datamatrix, UPCA etc. Other features include barcode insertion in PDF, Word and Excel documents. Also take image output in BMP, GIF, JPEG, PNG and WMF formats. You can also control image styles such as background color, bar color etc.

- Homepage of Aspose.BarCode for .NET: http://www.aspose.com/.net/barcode-component.aspx

- Download of Aspose.BarCode for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.barcode-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts