Write a 1D barcode to an image
In modern commerce and logistics operations, 1D barcodes serve as the foundational technology that enables rapid identification, tracking, and data capture across countless business processes. From the smallest retail products requiring UPC codes to large-scale manufacturing operations that depend on precise component tracking, the ability to generate professional-quality 1D barcodes programmatically represents a critical capability for organizations seeking to automate identification workflows and integrate barcode generation into their existing business systems.
This sample demonstrates the technical implementation of 1D barcode generation, showcasing how businesses can create high-quality, scannable barcodes that meet industry standards for retail, logistics, healthcare, and asset management applications. The capability extends beyond simple code generation to support sophisticated labeling workflows that enable inventory tracking, shipping logistics, point-of-sale integration, and compliance with industry-specific identification requirements.
Whether you’re developing retail systems that require UPC and EAN code generation for product labeling, implementing asset management solutions that need unique identifier creation for equipment tracking, or building healthcare applications that must generate medication and supply identification codes for regulatory compliance, the ability to programmatically create professional-grade 1D barcodes enables automation strategies that eliminate manual labeling processes while ensuring consistent quality and industry standard compliance.
Preparing the project
The first step is to initialize the SDK by registering the license. This needs to be done only once during the application’s lifetime and must occur before executing any further logic (see Getting Started with .NET SDK(opens in a new tab) for more details.)
using GdPicture14;
LicenseManager licence = new LicenseManager();licence.RegisterKEY(""); // Set your license keyCreating the image canvas
The 1D barcode generation process begins by creating a new image canvas that will contain the generated barcode with specified dimensions and background properties.
using GdPictureImaging imaging = new GdPictureImaging();
// Create a new image canvas with specified dimensions and color depthint imageId = imaging.CreateNewGdPictureImage(600, 300, 32, imaging.ARGBI(255, 255, 255, 255));The CreateNewGdPictureImage method creates a blank image canvas with the specified parameters: width (600 pixels), height (300 pixels), color depth (32-bit for full color support), and background color (white with full opacity). This provides a clean background for the barcode generation and ensures adequate space for the barcode plus any required quiet zones.
The ARGBI method creates a color value using Alpha, Red, Green, Blue, and Intensity components, enabling precise control over the canvas background color and ensuring optimal contrast for barcode scanning applications.
Generating the 1D barcode
The core generation process renders the barcode onto the image canvas with comprehensive customization options for format, positioning, size, and visual appearance.
// Generate 1D barcode with specified data and formatting parametersimaging.Barcode1DWrite(imageId, GdPicture14.Barcode1DWriterType.Barcode1DWriterCode128, "https://www.nutrient.io", 50, 50, 400, 100, imaging.ARGBI(255, 0, 0, 0), BarcodeAlign.BarcodeAlignLeft, 0);The Barcode1DWrite method generates the barcode with multiple configuration parameters that control every aspect of the output. The barcode type (Code128) provides high-density encoding suitable for alphanumeric data, while the positioning parameters (X: 50, Y: 50) and dimensions (width: 400, height: 100) ensure proper placement and sizing within the image canvas.
The color specification uses black bars (ARGBI 0,0,0 for maximum contrast) against the white background, ensuring optimal scanning performance across different devices and lighting conditions. The alignment parameter controls text positioning relative to the barcode, while the rotation parameter allows for orientation adjustments when needed.
Saving the generated barcode
The final step exports the image containing the barcode to a file format suitable for printing, distribution, or integration with labeling systems and business applications.
// Save the generated barcode image as PNG formatimaging.SaveAsPNG(imageId, @"output_barcode_1d.png");The SaveAsPNG method exports the image in PNG format, which provides lossless compression ideal for maintaining the sharp edges and high contrast necessary for reliable barcode scanning. PNG format ensures that the precise barcode dimensions and line definitions are preserved without compression artifacts that could affect scanning accuracy.
The verification step confirms successful file creation, providing quality assurance for automated generation workflows and ensuring the output is ready for use in labeling systems, printing processes, or digital distribution channels.
Supported Barcode Types
The SDK supports multiple 1D barcode formats for different use cases:
- Code 128: High-density alphanumeric encoding for general applications
- Code 39: Wide compatibility format for basic alphanumeric data
- UPC-A: Universal Product Code for retail products (12 digits)
- UPC-E: Compressed UPC format for smaller products (6 digits)
- EAN-13: European Article Number for international products
- EAN-8: Compressed EAN format for small products
- Code 93: Extended alphanumeric encoding with error detection
- Interleaved 2 of 5: Numeric-only format for logistics applications
Configuration Options
Customize barcode generation with extensive formatting options:
- Barcode Type: Choose from multiple 1D formats
- Size Control: Define width, height, and positioning
- Color Options: Set foreground and background colors
- Alignment: Left, center, or right alignment within the image
- Text Display: Include or exclude human-readable text
- Quiet Zones: Configure spacing around the barcode
Key Features
- Print-Ready Quality: High-resolution output suitable for professional printing
- Scalable Generation: Create barcodes from small labels to large signage
- Brand Integration: Customizable colors and layouts for brand consistency
- Batch Processing: Generate multiple barcodes efficiently for large inventories
- Format Flexibility: Output to PNG, JPEG, TIFF, or other image formats
Technical Benefits
- Memory-efficient image processing optimized for high-volume generation
- Vector-based rendering ensures crisp output at any resolution
- No external dependencies for barcode creation
- Consistent formatting across different output requirements
- Integration-ready for automated labeling systems and workflows
This implementation provides enterprise-grade 1D barcode generation capabilities essential for modern business operations, from simple product identification to complex supply chain management systems.