Saltar al pie de página
USO DE IRONBARCODE

Cómo Generar Código de Barras en VB.NET

Barcodes can be used to present data in a visible, computer-readable format. Initially, data in barcodes was represented by parallel lines that were spaced, widened, and sized differently. Various specialized optical scanners, known as barcode readers, can read these contemporary linear or one-dimensional (1D) barcodes. Later, two-dimensional (2D) variants of linear barcodes, which do not really employ bars, were developed and are known as matrix codes or 2D barcodes. Instead of using the standard barcodes, these versions employ rectangles, dots, hexagons, and other patterns. Various configurations of 2D optical scanners, made exclusively to read 2D barcodes, are available. A digital camera connected to a computer that runs software to take a photo of the barcode and decode it using the image is another way to read 2D barcodes. A mobile device with an inbuilt camera, such as a smartphone, can use the latter type of 2D barcode scanner by installing specific application software.

IronBarcode Features

The IronBarcode Library makes it simple to create dynamic barcodes. It helps us to encode barcode images with just a few lines of code. This straightforward library can create a barcode. Strong barcode generators built inside IronBarcode barcode readers allow them to create high-quality barcodes. IronBarcode allows us to create barcodes in VB.NET, C#, etc. Among various .NET libraries, this barcode generator simplifies reading your barcode using the barcode scanner.

  • IronBarcode can read and write most barcode image formats and QR standards, such as UPC A/E, Databar, EAN 8/13, MSI, Code 39/93/128, CodaBar, RSS 14/Expanded, and ITF.
  • It can correct rotation, noise, distortion, and skewing when reading scans and real-time video frames. IronBarcode automatically preprocesses barcode images while creating them to increase reading accuracy and speed.
  • IronBarcode supports batch processing with multi-core and multi-thread capabilities, beneficial for servers.
  • It can automatically locate one or more barcodes in single- and multipage documents.
  • IronBarcode is compatible with both the .NET Framework and .NET Core, supporting both 32-bit and 64-bit architectures.
  • On PC and mobile platforms, IronBarcode supports console, desktop, cloud, and internet applications.
  • IronBarcode can produce barcode images in various file and stream types, including PDF, JPG, TIFF, GIF, BMP, PNG, and HTML.

Creating a New Project in Visual Studio

Open Visual Studio, choose "New Project" from the file menu, then "Console App," "Windows Forms," or "WPF Application." In this article, we will be creating a Visual Basic Console App.

How to Generate Barcode in VB.NET: Figure 1

In the relevant text box, type the project name and choose the file path. Click the "Next" button.

How to Generate Barcode in VB.NET: Figure 2

Select the necessary .NET framework; for our tutorial, we are selecting .NET 6.0 and then clicking the "Create" button to create the project.

How to Generate Barcode in VB.NET: Figure 3

If you choose a console application, the project will now create the structure for that application and open the Program.cs file. You can now enter code and compile the program.

Next, download and install the IronBarcode library using the NuGet Package Manager command:

Install-Package BarCode

How to Generate Barcode in VB.NET: Figure 4

Alternatively, you can search for and download the "Barcode" package using the NuGet Package Manager, which will display all the search results. You can then choose the necessary package to download from them into the application.

How to Generate Barcode in VB.NET: Figure 5

Generate Barcode Using IronBarcode

Here is a sample VB.NET code for generating a barcode label using IronBarcode.

Imports System
Imports IronBarCode

Module Program
    Sub Main(args As String())
        ' Create a barcode with the text "Hello world" using Code128 encoding
        Dim barcode = BarcodeWriter.CreateBarcode("Hello world", BarcodeWriterEncoding.Code128, 500, 500)

        ' Add the barcode value text below the barcode
        barcode.AddBarcodeValueTextBelowBarcode()

        ' Save the barcode as a PNG image file
        barcode.SaveAsPng("demo.png")
    End Sub
End Module
Imports System
Imports IronBarCode

Module Program
    Sub Main(args As String())
        ' Create a barcode with the text "Hello world" using Code128 encoding
        Dim barcode = BarcodeWriter.CreateBarcode("Hello world", BarcodeWriterEncoding.Code128, 500, 500)

        ' Add the barcode value text below the barcode
        barcode.AddBarcodeValueTextBelowBarcode()

        ' Save the barcode as a PNG image file
        barcode.SaveAsPng("demo.png")
    End Sub
End Module
VB .NET

Explanation:

  • CreateBarcode: This function creates a barcode image with the given data. It takes parameters for the barcode content ("Hello world"), encoding type (BarcodeWriterEncoding.Code128), and dimensions (500x500 pixels).
  • AddBarcodeValueTextBelowBarcode: This method adds the encoded text below the barcode image.
  • SaveAsPng: This method saves the barcode image to the file path specified as "demo.png".

IronBarcode provides various options to create barcode images with different features, allowing adjustment and correction to provide high-quality images. We can also generate barcodes from text, streams, URLs, and other sources.

The output of the above code to generate barcodes in VB.NET using IronBarcode will look like below:

How to Generate Barcode in VB.NET: Figure 6

To know more about generating barcodes, click here for the tutorial.

Conclusion

Due to its effectiveness and adaptability to different operating systems, the IronBarcode library is an excellent choice for creating and identifying barcodes.

It provides numerous tools for designing and modifying various barcode kinds, including options to change text, barcode data color, line width, and height. Using VB.NET Crystal Reports is also supported by this barcode generator SDK, facilitating barcode creation and drawing in VB.NET.

The IronBarcode website, which offers both commercial and free versions for developers, contains licensing information about the library. Updates and support are offered without charge for a year.

Preguntas Frecuentes

¿Cómo puedo generar un código de barras usando VB.NET?

Para generar un código de barras usando VB.NET, puede utilizar la biblioteca IronBarcode. Primero, instale el paquete IronBarcode a través de NuGet en su proyecto de Visual Studio. Luego, use el método BarcodeWriter.CreateBarcode para codificar y generar una imagen de código de barras.

¿Cuáles son las ventajas de usar IronBarcode para la generación de códigos de barras?

IronBarcode simplifica la generación de códigos de barras al proporcionar métodos fáciles de usar para codificar imágenes de códigos de barras con un mínimo de código. Soporta múltiples formatos de código de barras, como UPC, EAN y Code 39/128, y mejora la velocidad y precisión a través de características automáticas de preprocesamiento de imágenes y procesamiento por lotes.

¿Cómo puedo leer códigos de barras usando un dispositivo móvil?

Los dispositivos móviles con cámara pueden leer códigos de barras usando software de aplicación específico que procesa la imagen y decodifica el código de barras. IronBarcode facilita esto al soportar formatos de código de barras 2D compatibles con aplicaciones de escaneo de códigos de barras móviles.

¿Es posible personalizar las características de los códigos de barras usando IronBarcode?

Sí, IronBarcode permite a los desarrolladores personalizar varias características de los códigos de barras, incluyendo el tipo, tamaño y color del código. Esto se logra a través de modificaciones directas en los métodos de la biblioteca para la generación de códigos de barras.

¿Se puede usar IronBarcode para crear códigos de barras en diferentes formatos de archivo?

IronBarcode soporta la exportación de imágenes de códigos de barras a múltiples formatos de archivo, como PDF, PNG, JPG, TIFF, GIF, BMP y HTML, proporcionando flexibilidad para diversas necesidades de aplicación.

¿Qué plataformas y marcos de trabajo soportan la generación de códigos de barras con IronBarcode?

IronBarcode es compatible con tanto .NET Framework como .NET Core, permitiendo a los desarrolladores crear aplicaciones de códigos de barras en diversas plataformas, incluyendo aplicaciones de consola, escritorio, nube e Internet para dispositivos PC y móviles.

¿Cómo puedo instalar la biblioteca IronBarcode en un proyecto VB.NET?

La biblioteca IronBarcode se puede instalar en un proyecto VB.NET a través del Administrador de Paquetes NuGet en Visual Studio. Use el comando: Install-Package IronBarCode para integrarlo fácilmente en su proyecto.

¿IronBarcode soporta el procesamiento por lotes de códigos de barras?

Sí, IronBarcode soporta el procesamiento por lotes, lo que permite capacidades de procesamiento multicore y multihilo. Esto es particularmente útil para aplicaciones de servidor que requieren procesar grandes volúmenes de imágenes de códigos de barras de manera eficiente.

¿Cuáles son las opciones de licencia disponibles para IronBarcode?

IronBarcode ofrece tanto versiones comerciales como gratuitas para desarrolladores. La biblioteca proporciona actualizaciones y soporte gratuito durante un año, asegurando que los desarrolladores tengan acceso a las últimas características y asistencia cuando sea necesario.

Jordi Bardia
Ingeniero de Software
Jordi es más competente en Python, C# y C++. Cuando no está aprovechando sus habilidades en Iron Software, está programando juegos. Compartiendo responsabilidades para pruebas de productos, desarrollo de productos e investigación, Jordi agrega un valor inmenso a la mejora continua del producto. La experiencia variada lo mantiene ...
Leer más