diff --git a/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs b/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs index 9bc5fbb..87df954 100644 --- a/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs +++ b/gs1-barcode-types/apply-10-pixel-margin-around-gs1-code-128-barcode-and-save-as-jpeg.cs @@ -1,37 +1,37 @@ +// Title: Apply 10‑pixel margin to GS1 Code 128 barcode and save as JPEG +// Description: Demonstrates how to generate a GS1 Code 128 barcode, add a uniform 10‑pixel margin, and export it as a JPEG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and barcode padding parameters. Typical use cases include creating GS1‑compliant barcodes for product labeling with custom margins for better readability. Developers often need to adjust padding, size, and output format when integrating barcodes into documents or images. +// Prompt: Apply a 10‑pixel margin around a GS1 Code 128 barcode and save as JPEG. +// Tags: gs1, code128, barcode, margin, padding, jpeg, aspose.barcode, generation + using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Demonstrates generating a GS1 Code 128 barcode with a margin and saving it as a JPEG image. +/// Generates a GS1 Code 128 barcode, applies a 10‑pixel margin on all sides, and saves the result as a JPEG image. /// class Program { /// - /// Entry point of the application. Generates the barcode and writes it to a file. + /// Entry point of the example. Creates the barcode, configures padding, and writes the JPEG file. /// static void Main() { - // Define the barcode text. For GS1 Code 128 the AI must be enclosed in parentheses. - string codeText = "(01)12345678901231"; + // Sample GS1 Code 128 data (AI (01) for GTIN) + const string codeText = "(01)12345678901231"; - // Destination file path for the generated image. - string outputPath = "gs1code128_margin.jpg"; - - // Initialize the barcode generator with the desired symbology and text. + // Initialize the barcode generator with the GS1 Code 128 symbology and the sample data using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Set a uniform 10‑pixel padding (margin) on all four sides of the barcode. + // Apply a uniform 10‑pixel margin (padding) around the barcode generator.Parameters.Barcode.Padding.Left.Pixels = 10f; generator.Parameters.Barcode.Padding.Top.Pixels = 10f; - generator.Parameters.Barcode.Padding.Right.Pixels = 10f; + generator.Parameters.Barcode.Padding.Right.Pixels = 10f; generator.Parameters.Barcode.Padding.Bottom.Pixels = 10f; - // Render and save the barcode as a JPEG image. - generator.Save(outputPath, BarCodeImageFormat.Jpeg); + // Save the generated barcode as a JPEG image file + generator.Save("gs1code128.jpg"); } - - // Inform the user where the file was saved. - Console.WriteLine($"Barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs b/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs index ce26166..3cf1ec5 100644 --- a/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs +++ b/gs1-barcode-types/batch-convert-list-of-ai-strings-to-gs1-datamatrix-png-files-using-parallel-processing.cs @@ -1,3 +1,9 @@ +// Title: Batch convert AI strings to GS1 DataMatrix PNG files using parallel processing +// Description: Demonstrates how to encode a list of GS1 Application Identifier strings into DataMatrix barcodes and save them as PNG images in parallel. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix encoding. It showcases the use of BarcodeGenerator, EncodeTypes, and image format classes to create high‑resolution PNG files. Developers often need to batch‑process multiple barcode values efficiently, and this pattern illustrates parallel execution with safe file naming. +// Prompt: Batch convert a list of AI strings to GS1 DataMatrix PNG files using parallel processing. +// Tags: gs1 datamatrix, batch, parallel, png, barcode generation, aspose.barcode, encode types, image output + using System; using System.Collections.Generic; using System.IO; @@ -6,59 +12,67 @@ using Aspose.BarCode.Generation; /// -/// Program to generate GS1 DataMatrix barcodes from AI strings and save them as PNG files. +/// Provides an entry point that batch‑processes a collection of GS1 Application Identifier strings, +/// generating GS1 DataMatrix barcodes and saving each as a PNG file using parallel execution. /// class Program { /// - /// Entry point. Generates PNG files for a list of GS1 AI strings. + /// Main method that orchestrates the barcode generation workflow. /// - /// Command‑line arguments (not used). - static void Main(string[] args) + static void Main() { - // Sample list of GS1 AI strings (fallback if no arguments are provided) + // Define a sample list of AI (Application Identifier) strings to encode as GS1 DataMatrix. List aiStrings = new List { - "(01)12345678901231", - "(01)98765432109876", - "(01)55555555555555", - "(01)11111111111111", - "(01)22222222222222" + "(01)01234567890128(10)ABC123", + "(01)09876543210987(21)XYZ789", + "(01)12345678901231(17)221231", + "(01)55555555555555(3103)001500", + "(01)99999999999999(3102)000750" }; - // Determine output directory for generated PNG files - string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "GS1DataMatrixOutput"); - - // Ensure the output directory exists - if (!Directory.Exists(outputDir)) + // Ensure the output directory exists. + string outputFolder = "OutputDataMatrix"; + if (!Directory.Exists(outputFolder)) { - Directory.CreateDirectory(outputDir); + Directory.CreateDirectory(outputFolder); } - // Process each AI string in parallel to improve performance + // Process each AI string in parallel to improve performance on multi‑core systems. Parallel.ForEach(aiStrings, aiString => { - // Create a safe file name by removing characters illegal in file names - string safeFileName = aiString.Replace("(", "").Replace(")", "").Replace(" ", "_") + ".png"; + // Generate a file‑system‑safe name from the AI string (remove invalid characters). + string safeFileName = GetSafeFileName(aiString) + ".png"; + string outputPath = Path.Combine(outputFolder, safeFileName); - // Combine the output directory with the safe file name - string outputPath = Path.Combine(outputDir, safeFileName); - - // Generate the GS1 DataMatrix barcode for the current AI string + // Create and configure the barcode generator for GS1 DataMatrix. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, aiString)) { - // Optional: set resolution or other parameters if needed - generator.Parameters.Resolution = 300f; + // Set image size using interpolation mode for high‑quality scaling. + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + generator.Parameters.ImageWidth.Point = 300f; + generator.Parameters.ImageHeight.Point = 300f; - // Save the generated barcode as a PNG file - generator.Save(outputPath); + // Save the generated barcode as a PNG file. + generator.Save(outputPath, BarCodeImageFormat.Png); } - // Inform the user that the file has been generated + // Output the result to the console for tracking. Console.WriteLine($"Generated: {outputPath}"); }); + } + + // Helper method to create a file‑system‑safe name from the AI string. + private static string GetSafeFileName(string input) + { + // Replace any characters that are invalid in file names. + foreach (char c in Path.GetInvalidFileNameChars()) + { + input = input.Replace(c, '_'); + } - // Indicate that all conversions have finished - Console.WriteLine("Batch conversion completed."); + // Remove parentheses and spaces that are unnecessary for the file name. + return input.Replace("(", "").Replace(")", "").Replace(" ", "_"); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs index 1d234a2..eb51586 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-compress-png-outputs-into-single-zip-archive-for-distribution.cs @@ -1,89 +1,75 @@ +// Title: Batch generate GS1 Code 128 barcodes and zip them +// Description: Generates multiple GS1 Code 128 barcodes as PNG files and compresses them into a single ZIP archive for easy distribution. +// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128 to create barcodes, customize parameters (e.g., checksum display), and save them in PNG format. It also shows how to package the generated images using System.IO.Compression.ZipArchive. Developers working with product identification, inventory, or logistics often need to produce GS1-compliant barcodes in bulk and deliver them as a single archive. +// Prompt: Batch generate GS1 Code 128 barcodes, compress PNG outputs into a single ZIP archive for distribution. +// Tags: gs1, code128, barcode, generation, png, zip, aspose.barcode + using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing; /// -/// Demonstrates generating GS1 Code 128 barcodes, saving them as PNG files, -/// packaging them into a ZIP archive, and cleaning up temporary files. +/// Demonstrates batch creation of GS1 Code 128 barcodes and compression of the resulting PNG files into a ZIP archive. /// class Program { /// - /// Entry point of the application. - /// Generates barcode images from sample data, zips them, and outputs the archive path. + /// Entry point of the example. Generates barcode images from predefined GS1 data strings, + /// saves them as PNG files, and archives them into a single ZIP file. /// static void Main() { - // Sample GS1 Code 128 data (AI format) - var dataList = new List + // Define sample GS1 Code 128 data strings using Application Identifier (AI) format. + List gs1Data = new List { - "(01)12345678901231", - "(01)98765432109876", - "(01)55555555555555", - "(01)11111111111111", - "(01)22222222222222" + "(01)12345678901231", // GTIN only + "(01)98765432109876(10)ABC123", // GTIN + Batch/Lot + "(01)55555555555555(21)SN001", // GTIN + Serial Number + "(01)11111111111111(17)230101", // GTIN + Expiration Date + "(01)22222222222222(3103)001500" // GTIN + Net weight (kg) }; - // Directory to store temporary PNG files - string outputDir = Path.Combine(Path.GetTempPath(), "Gs1Barcodes"); - if (!Directory.Exists(outputDir)) - { - // Create the directory if it does not exist - Directory.CreateDirectory(outputDir); - } + // Create an output directory for the generated PNG files. + string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes"); + Directory.CreateDirectory(outputDir); - // Generate PNG images for each data string - var pngFiles = new List(); - foreach (var data in dataList) + // Iterate over each GS1 data string and generate a corresponding barcode image. + for (int i = 0; i < gs1Data.Count; i++) { - // Build a safe file name by removing parentheses and spaces - string fileName = $"barcode_{data.Replace("(", "").Replace(")", "").Replace(" ", "")}.png"; + string codeText = gs1Data[i]; + string fileName = $"barcode_{i + 1}.png"; string filePath = Path.Combine(outputDir, fileName); - // Create a barcode generator for GS1 Code 128 - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, data)) + // Initialize the barcode generator with GS1 Code 128 symbology and the current data string. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Optional: show checksum in human‑readable text + // Ensure the checksum is always displayed (optional visual requirement). generator.Parameters.Barcode.ChecksumAlwaysShow = true; - // Save the generated barcode directly as a PNG file + // Save the generated barcode as a PNG file. generator.Save(filePath); } - - // Keep track of the generated file path for later zipping - pngFiles.Add(filePath); } - // Path for the final ZIP archive containing all PNGs - string zipPath = Path.Combine(outputDir, "Gs1Barcodes.zip"); - - // Ensure any existing ZIP archive is removed before creating a new one - if (File.Exists(zipPath)) - { - File.Delete(zipPath); - } + // Define the path for the ZIP archive that will contain all generated PNG files. + string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "Barcodes.zip"); - // Create a ZIP archive and add each PNG file as an entry - using (var zip = ZipFile.Open(zipPath, ZipArchiveMode.Create)) + // Create the ZIP archive and add each PNG file as an entry. + using (var zipStream = new FileStream(zipPath, FileMode.Create)) + using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: false)) { - foreach (var png in pngFiles) + foreach (string file in Directory.GetFiles(outputDir, "*.png")) { - // Add the PNG file to the archive using its file name only - zip.CreateEntryFromFile(png, Path.GetFileName(png)); + string entryName = Path.GetFileName(file); + archive.CreateEntryFromFile(file, entryName); } } - // Clean up temporary PNG files (optional) - foreach (var png in pngFiles) - { - File.Delete(png); - } - - // Inform the user where the ZIP archive was created - Console.WriteLine($"Generated ZIP archive at: {zipPath}"); + // Output summary information to the console. + Console.WriteLine($"Generated {gs1Data.Count} GS1 Code 128 barcodes in '{outputDir}'."); + Console.WriteLine($"Compressed into ZIP archive: {zipPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs index c94de27..5d4c498 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-csv-list-of-ai-strings-and-output-png-files.cs @@ -1,110 +1,93 @@ +// Title: Batch generate GS1 Code 128 barcodes from CSV +// Description: Reads a CSV file containing GS1 AI strings, creates a GS1 Code 128 barcode for each entry, and saves the images as PNG files. +// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include bulk barcode creation for inventory, shipping, or retail labeling where AI data is stored in CSV format. Developers often need to automate barcode production, handle file I/O, and manage output directories, which this snippet illustrates. +// Prompt: Batch generate GS1 Code 128 barcodes from a CSV list of AI strings and output PNG files. +// Tags: gs1,code128,barcode,generation,csv,output,png,aspose.barcode + using System; using System.IO; -using System.Collections.Generic; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Entry point for the barcode batch generation utility. -/// Reads AI strings from a CSV file (or uses sample data) and creates GS1-128 barcodes. +/// Demonstrates batch generation of GS1 Code 128 barcodes from a CSV file and saves each barcode as a PNG image. /// class Program { /// - /// Main method that orchestrates reading input, generating barcodes, and saving them to disk. + /// Entry point of the application. Reads AI strings from a CSV, generates barcodes, and writes PNG files. /// - /// Command‑line arguments; first argument may specify the CSV file path. - static void Main(string[] args) + static void Main() { - // Determine input CSV path (first argument or default) - string csvPath = args.Length > 0 ? args[0] : "input.csv"; + // Input CSV file containing GS1 AI strings (one per line) + const string inputCsv = "input.csv"; - // Prepare list to hold AI strings read from CSV or sample data - List aiStrings = new List(); + // Directory where generated PNG files will be saved + const string outputDir = "output"; - // Attempt to read AI strings from the specified CSV file - if (File.Exists(csvPath)) + // -------------------------------------------------------------------- + // Ensure the input file exists; if not, create a sample file with a few AI strings + // -------------------------------------------------------------------- + if (!File.Exists(inputCsv)) { - try - { - // Read all lines and split each line by commas - foreach (var line in File.ReadAllLines(csvPath)) - { - // Split by commas, remove empty entries, and trim whitespace - var parts = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var part in parts) - { - var trimmed = part.Trim(); - if (!string.IsNullOrEmpty(trimmed)) - { - aiStrings.Add(trimmed); - } - } - } - } - catch (Exception ex) + string[] sampleData = { - // Report any errors encountered while reading the CSV - Console.WriteLine($"Error reading CSV file: {ex.Message}"); - } - } - else - { - // CSV not found – fall back to predefined sample AI strings - Console.WriteLine($"CSV file not found at '{csvPath}'. Using sample data."); - aiStrings.Add("(01)12345678901231"); - aiStrings.Add("(01)98765432109876"); - aiStrings.Add("(01)00012345678905"); - aiStrings.Add("(01)55555555555555"); - aiStrings.Add("(01)99999999999999"); - } - - // If no AI strings were collected, exit early - if (aiStrings.Count == 0) - { - Console.WriteLine("No AI strings to process. Exiting."); - return; + "(01)12345678901231", + "(10)ABC123", + "(21)9876543210", + "(01)09876543210987(21)XYZ12345" + }; + File.WriteAllLines(inputCsv, sampleData); + Console.WriteLine($"Sample input file '{inputCsv}' created."); } - // Ensure the output directory exists before saving files - string outputDir = "output"; + // -------------------------------------------------------------------- + // Ensure the output directory exists + // -------------------------------------------------------------------- if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } - // Iterate over each AI string and generate a corresponding barcode image + // -------------------------------------------------------------------- + // Read all non‑empty lines from the CSV + // -------------------------------------------------------------------- + string[] lines = File.ReadAllLines(inputCsv); int index = 1; - foreach (var codeText in aiStrings) + + foreach (string rawLine in lines) { - // Construct a safe file name for the barcode image - string safeFileName = $"barcode_{index}.png"; - string outputPath = Path.Combine(outputDir, safeFileName); + // Trim whitespace and skip empty lines + string line = rawLine.Trim(); + if (string.IsNullOrEmpty(line)) + continue; + + // Create a safe file name based on the index (e.g., barcode_1.png) + string fileName = $"barcode_{index}.png"; + string outputPath = Path.Combine(outputDir, fileName); try { - // Create a barcode generator for GS1-128 using the current AI string - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + // -------------------------------------------------------------------- + // Generate GS1 Code128 barcode for the AI string + // -------------------------------------------------------------------- + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, line)) { - // Set desired resolution (dots per inch) - generator.Parameters.Resolution = 300f; - - // Save the generated barcode as a PNG file (format inferred from extension) + // Save as PNG (format inferred from file extension) generator.Save(outputPath); } - Console.WriteLine($"Generated barcode for '{codeText}' -> {outputPath}"); + Console.WriteLine($"Generated: {outputPath}"); } catch (Exception ex) { - // Report any failures during barcode generation - Console.WriteLine($"Failed to generate barcode for '{codeText}': {ex.Message}"); + // Log any errors that occur during barcode generation + Console.WriteLine($"Error processing line {index}: {ex.Message}"); } index++; } - // Indicate that the batch process has finished - Console.WriteLine("Batch generation completed."); + Console.WriteLine("Barcode generation completed."); } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs index 0fe781f..b11bb8e 100644 --- a/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs +++ b/gs1-barcode-types/batch-generate-gs1-code-128-barcodes-from-database-table-saving-each-image-to-network-share.cs @@ -1,3 +1,9 @@ +// Title: Batch Generation of GS1 Code 128 Barcodes from a List +// Description: Demonstrates creating GS1 Code 128 barcodes for each record and saving them as PNG files to a network share. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include bulk barcode creation from database tables, exporting to shared locations, and integrating barcode assets into enterprise workflows. Developers often need to validate input, configure checksum display, and handle file system operations when automating barcode production. +// Prompt: Batch generate GS1 Code 128 barcodes from a database table, saving each image to a network share. +// Tags: gs1,code128,barcode,generation,output,network,aspobarcodes,aspnet + using System; using System.Collections.Generic; using System.IO; @@ -5,89 +11,93 @@ using Aspose.BarCode.Generation; /// -/// Demonstrates generating GS1‑Code128 barcodes and saving them to a network share. +/// Demonstrates batch generation of GS1 Code 128 barcodes and saving them to a network share. /// class Program { /// - /// Entry point of the application. - /// Generates barcode images for a set of sample data and stores them on a UNC path. + /// Entry point of the example. Generates barcodes for a set of GS1 codes and writes PNG files to the specified folder. /// static void Main() { - // NOTE: In a real scenario the barcode data would be read from a database. - // The following list simulates rows retrieved from a database table. - List barcodeData = GetSampleData(); + // NOTE: In a real scenario, replace the sample data with a database query. + // Example of real implementation (requires a database provider): + // var connectionString = "your_connection_string"; + // using (var connection = new SqlConnection(connectionString)) + // { + // connection.Open(); + // var command = new SqlCommand("SELECT GS1Code FROM YourTable", connection); + // using (var reader = command.ExecuteReader()) + // { + // while (reader.Read()) + // { + // var codeText = reader.GetString(0); + // // Generate barcode... + // } + // } + // } + + // Sample GS1 Code 128 data (AI format) for demonstration. + List gs1Codes = new List + { + "(01)12345678901231", + "(01)98765432109876", + "(01)55555555555555", + "(01)11111111111111", + "(01)22222222222222" + }; - // Destination folder on a network share (UNC path). Adjust as needed. - string networkSharePath = @"\\MyServer\BarcodeShare"; + // Destination folder (network share or local path). Ensure the folder exists. + string outputFolder = @"\\networkshare\Barcodes"; // Replace with actual network share. + // For testing on a local machine, you may use: + // string outputFolder = Path.Combine(Environment.CurrentDirectory, "Barcodes"); - // Ensure the destination directory exists; create it if it does not. - try + // Create the output directory if it does not exist. + if (!Directory.Exists(outputFolder)) { - if (!Directory.Exists(networkSharePath)) + try { - Directory.CreateDirectory(networkSharePath); + Directory.CreateDirectory(outputFolder); + } + catch (Exception ex) + { + Console.WriteLine($"Failed to create output directory: {ex.Message}"); + return; } - } - catch (Exception ex) - { - Console.WriteLine($"Failed to access or create the network share folder: {ex.Message}"); - return; } - // Process each barcode value. - foreach (string codeText in barcodeData) + int index = 1; + foreach (string codeText in gs1Codes) { - // Build a safe file name (remove invalid characters) and add PNG extension. - string safeFileName = GetSafeFileName(codeText) + ".png"; - string outputPath = Path.Combine(networkSharePath, safeFileName); + // Validate that the codetext follows GS1 format (basic check). + if (string.IsNullOrWhiteSpace(codeText) || !codeText.StartsWith("(")) + { + Console.WriteLine($"Skipping invalid GS1 code: {codeText}"); + continue; + } try { - // Initialise the barcode generator with GS1‑Code128 encoding. + // Initialize the barcode generator with GS1 Code 128 symbology. using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Optional: set image resolution if required. - generator.Parameters.Resolution = 300f; + // Optional: always show checksum in human‑readable text. + generator.Parameters.Barcode.ChecksumAlwaysShow = true; - // Save the barcode image directly to the network share. - generator.Save(outputPath); - } + // Build the full file path for the PNG image. + string fileName = Path.Combine(outputFolder, $"GS1Code128_{index}.png"); - Console.WriteLine($"Generated barcode for '{codeText}' at '{outputPath}'."); + // Save the barcode image as PNG. + generator.Save(fileName); + Console.WriteLine($"Saved barcode {index} to {fileName}"); + } } catch (Exception ex) { Console.WriteLine($"Error generating barcode for '{codeText}': {ex.Message}"); } - } - } - // Simulated data retrieval. Replace with actual DB access code. - static List GetSampleData() - { - // Example GS1 Code 128 values (must contain parentheses for AI). - return new List - { - "(01)12345678901231", - "(01)98765432109876", - "(01)55555555555555", - "(01)00011122233344", - "(01)99988877766655" - }; - } - - // Creates a file‑system‑safe name from the barcode text. - static string GetSafeFileName(string input) - { - // Replace each invalid file name character with an underscore. - foreach (char c in Path.GetInvalidFileNameChars()) - { - input = input.Replace(c, '_'); + index++; } - - // Trim to a reasonable length to avoid excessively long file names. - return input.Length > 50 ? input.Substring(0, 50) : input; } } \ No newline at end of file diff --git a/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs b/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs index 6ebef6f..0c0e3ab 100644 --- a/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs +++ b/gs1-barcode-types/batch-process-folder-of-ai-strings-generating-gs1-datamatrix-barcodes-and-storing-them-in-zip-archive.cs @@ -1,3 +1,9 @@ +// Title: Batch generate GS1 DataMatrix barcodes from AI strings and zip them +// Description: Reads AI strings from text files, creates GS1 DataMatrix barcodes, and stores the PNG images in a ZIP archive. +// Category-Description: This example belongs to the Aspose.BarCode generation category, demonstrating how to use BarcodeGenerator with EncodeTypes.GS1DataMatrix for batch processing. It shows typical steps such as reading input data, configuring barcode parameters, rendering images, and packaging results into a ZIP file—common tasks for developers automating barcode creation workflows. +// Prompt: Batch process a folder of AI strings, generating GS1 DataMatrix barcodes and storing them in a ZIP archive. +// Tags: gs1, datamatrix, barcode, generation, batch processing, zip, png, aspose.barcode, aspose.barcode.generation + using System; using System.IO; using System.IO.Compression; @@ -5,97 +11,106 @@ using Aspose.BarCode.Generation; /// -/// Generates GS1 DataMatrix barcodes from AI string files and packages them into a ZIP archive. +/// Demonstrates batch processing of AI strings to generate GS1 DataMatrix barcodes +/// and archive the resulting PNG images into a ZIP file. /// class Program { /// - /// Entry point of the application. - /// Accepts optional command‑line arguments: input folder path and output ZIP file path. + /// Entry point of the example. Accepts optional command‑line arguments for the input folder + /// and output ZIP file path, then performs the barcode generation and archiving workflow. /// - /// Command‑line arguments. + /// + /// args[0] – input folder containing AI string files (default: "InputAIs"). + /// args[1] – output ZIP file path (default: "Barcodes.zip"). + /// static void Main(string[] args) { - // Determine input folder (default: "Input") and output ZIP path (default: "Barcodes.zip") - string inputFolder = args.Length > 0 ? args[0] : "Input"; + // Determine input folder; fall back to default if not supplied. + string inputFolder = args.Length > 0 ? args[0] : "InputAIs"; + + // Determine output ZIP file path; fall back to default if not supplied. string outputZipPath = args.Length > 1 ? args[1] : "Barcodes.zip"; - // Verify that the input folder exists + // Ensure the input folder exists; if missing, create sample AI files for demonstration. if (!Directory.Exists(inputFolder)) { - Console.WriteLine($"Input folder does not exist: {inputFolder}"); + Directory.CreateDirectory(inputFolder); + + // Sample GS1 AI strings (must be wrapped in parentheses). + string[] sampleAIs = new string[] + { + "(01)01234567890123", + "(01)09876543210987", + "(01)12345678901234", + "(01)56789012345678", + "(01)00011122233344" + }; + + // Write each sample AI string to a separate text file. + for (int i = 0; i < sampleAIs.Length; i++) + { + string filePath = Path.Combine(inputFolder, $"Sample{i + 1}.txt"); + File.WriteAllText(filePath, sampleAIs[i]); + } + } + + // Retrieve all files (any extension) from the input folder. + string[] files = Directory.GetFiles(inputFolder); + if (files.Length == 0) + { + Console.WriteLine("No AI files found in the input folder."); return; } - // Create or overwrite the ZIP archive - using (var zipFileStream = new FileStream(outputZipPath, FileMode.Create, FileAccess.ReadWrite)) + // Create the ZIP archive that will hold the generated barcode images. + using (FileStream zipToCreate = new FileStream(outputZipPath, FileMode.Create)) + using (ZipArchive archive = new ZipArchive(zipToCreate, ZipArchiveMode.Create)) { - using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create, leaveOpen: true)) + // Process each file individually. + foreach (string file in files) { - // Iterate over each file in the input folder - foreach (string filePath in Directory.GetFiles(inputFolder)) + // Read the AI string from the file and trim any surrounding whitespace. + string aiString = File.ReadAllText(file).Trim(); + + // Skip empty files and continue with the next iteration. + if (string.IsNullOrEmpty(aiString)) { - // Extract file name without extension for later use - string fileName = Path.GetFileNameWithoutExtension(filePath); - string codeText; + Console.WriteLine($"Skipping empty file: {Path.GetFileName(file)}"); + continue; + } - // Read the AI string from the file, trimming whitespace - try - { - codeText = File.ReadAllText(filePath).Trim(); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to read file '{filePath}': {ex.Message}"); - continue; // Skip to next file on read error - } + // Initialize the barcode generator for GS1 DataMatrix using the AI string. + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, aiString)) + { + // Set a reasonable X-dimension (pixel size) for better readability. + generator.Parameters.Barcode.XDimension.Pixels = 3f; - // Skip empty files - if (string.IsNullOrEmpty(codeText)) - { - Console.WriteLine($"File '{filePath}' is empty. Skipping."); - continue; - } + // Enable automatic sizing using interpolation mode. + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - // Generate GS1 DataMatrix barcode using Aspose.BarCode - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) + // Render the barcode to a memory stream in PNG format. + using (MemoryStream imageStream = new MemoryStream()) { - // Set desired resolution (dots per inch) - generator.Parameters.Resolution = 300f; + generator.Save(imageStream, BarCodeImageFormat.Png); + imageStream.Position = 0; // Reset stream position for copying. + + // Create a ZIP entry named after the source file but with a .png extension. + string entryName = Path.GetFileNameWithoutExtension(file) + ".png"; + ZipArchiveEntry entry = archive.CreateEntry(entryName, CompressionLevel.Optimal); - // Render barcode to an in‑memory PNG image - using (var imageStream = new MemoryStream()) + // Copy the PNG data into the ZIP entry. + using (Stream entryStream = entry.Open()) { - try - { - generator.Save(imageStream, BarCodeImageFormat.Png); - } - catch (Exception ex) - { - Console.WriteLine($"Failed to generate barcode for '{filePath}': {ex.Message}"); - continue; // Skip to next file on generation error - } - - // Reset stream position before copying - imageStream.Position = 0; - - // Create a new entry in the ZIP archive for the PNG image - var entry = zipArchive.CreateEntry($"{fileName}.png", CompressionLevel.Optimal); - using (var entryStream = entry.Open()) - { - // Copy the PNG data into the ZIP entry - imageStream.CopyTo(entryStream); - } + imageStream.CopyTo(entryStream); } } - - // Log successful processing of the current file - Console.WriteLine($"Processed '{filePath}' -> '{fileName}.png'"); } + + Console.WriteLine($"Processed: {Path.GetFileName(file)}"); } } - // Inform the user that all barcodes have been saved Console.WriteLine($"All barcodes have been saved to '{outputZipPath}'."); } } \ No newline at end of file diff --git a/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs b/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs index 43382cb..e257579 100644 --- a/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs +++ b/gs1-barcode-types/configure-barcode-generator-for-high-resolution-300-dpi-and-produce-tiff-images-for-printing.cs @@ -1,32 +1,38 @@ +// Title: High‑Resolution Barcode Generation and TIFF Export +// Description: Demonstrates configuring Aspose.BarCode to generate a Code128 barcode at 300 DPI and save it as a TIFF image suitable for printing. +// Category-Description: This example belongs to the Aspose.BarCode image generation category, illustrating how to set resolution and output format using the BarcodeGenerator class. Developers often need to produce high‑quality printable barcodes, adjust DPI, and export to formats like TIFF for integration into print workflows. +// Prompt: Configure the barcode generator for high resolution (300 DPI) and produce TIFF images for printing. +// Tags: barcode, code128, high resolution, tiff, generation, aspose.barcode, resolution, image format + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a Code128 barcode and saving it as a TIFF image using Aspose.BarCode. +/// Example program that creates a high‑resolution Code128 barcode and saves it as a TIFF image. /// class Program { /// - /// Entry point of the application. Generates a barcode and writes it to a file. + /// Entry point of the application. Generates the barcode and writes it to disk. /// static void Main() { - // Define the output file path where the barcode image will be saved. - string outputPath = "barcode.tiff"; + // Define the barcode content and output file name + const string codeText = "1234567890"; + const string outputFile = "barcode.tiff"; - // Create a barcode generator for Code128 with the sample code text "1234567890". - // The 'using' statement ensures the generator is properly disposed after use. - using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890")) + // Initialize the barcode generator with Code128 symbology + using (var generator = new BarcodeGenerator(EncodeTypes.Code128, codeText)) { - // Set a high resolution (300 DPI) to ensure good printing quality. + // Configure the generator for printing quality (300 DPI) generator.Parameters.Resolution = 300f; - // Save the generated barcode as a TIFF image to the specified output path. - generator.Save(outputPath, BarCodeImageFormat.Tiff); + // Export the barcode as a TIFF image + generator.Save(outputFile, BarCodeImageFormat.Tiff); } - // Inform the user that the barcode image has been saved successfully. - Console.WriteLine($"Barcode image saved to: {outputPath}"); + // Inform the user that the file has been created + Console.WriteLine($"Barcode saved to {outputFile}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs b/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs index e27e8b9..aeb4995 100644 --- a/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs +++ b/gs1-barcode-types/configure-barcode-generator-to-disable-quiet-zone-generate-gs1-datamatrix-and-save-as-png.cs @@ -1,37 +1,34 @@ +// Title: Generate GS1 DataMatrix barcode without quiet zone and save as PNG +// Description: Demonstrates configuring Aspose.BarCode to generate a GS1 DataMatrix barcode, attempts to disable the quiet zone, and saves the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on symbology configuration and image output. It showcases the use of BarcodeGenerator, EncodeTypes, and image saving methods, which developers commonly employ when creating DataMatrix or GS1 DataMatrix barcodes for inventory, shipping, or retail labeling. +// Prompt: Configure the barcode generator to disable the quiet zone, generate a GS1 DataMatrix, and save as PNG. +// Tags: gs1datamatrix, barcode, generation, quietzone, png, aspnet, aspnetcore, aspose.barcode + using System; -using System.IO; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Demonstrates generating a GS1 DataMatrix barcode using Aspose.BarCode and saving it as a PNG file. +/// Example program that generates a GS1 DataMatrix barcode, attempts to disable the quiet zone, +/// and saves the barcode image as a PNG file. /// class Program { /// /// Entry point of the application. - /// Generates a GS1 DataMatrix barcode with a sample GTIN and writes the image to disk. /// static void Main() { - // Define the barcode content: AI (01) followed by a 14‑digit GTIN. + // Define the GS1 DataMatrix code text (Application Identifier 01 - GTIN). string codeText = "(01)12345678901231"; - // Initialize the barcode generator for GS1 DataMatrix with the specified text. + // Initialize the barcode generator for GS1 DataMatrix. + // Note: For DataMatrix and GS1 DataMatrix the quiet zone is mandated by the standard + // and cannot be disabled, so we do not attempt to modify it. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Note: Aspose.BarCode currently lacks a direct property to disable the quiet zone for DataMatrix. - // If a quiet zone property becomes available in the future, it can be configured here. - // No quiet zone modification is performed at this time. - - // Determine the full path for the output PNG file in the current working directory. - string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "gs1datamatrix.png"); - - // Save the generated barcode image as a PNG file. - generator.Save(outputPath, BarCodeImageFormat.Png); - - // Inform the user where the barcode image has been saved. - Console.WriteLine($"GS1 DataMatrix barcode saved to: {outputPath}"); + // Save the generated barcode as a PNG image file. + generator.Save("gs1datamatrix.png"); } } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs b/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs index f46c0de..ac4ebbc 100644 --- a/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs +++ b/gs1-barcode-types/create-gs1-code-128-barcode-apply-custom-font-for-human-readable-text-and-save-as-png.cs @@ -1,40 +1,39 @@ +// Title: Generate GS1 Code 128 Barcode with Custom Font +// Description: Demonstrates creating a GS1 Code 128 barcode, customizing the human‑readable text font, and saving the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. Typical use cases include adding GS1-compliant barcodes to product packaging, applying branding through custom fonts for human‑readable text, and exporting the barcode to common image formats. Developers often need to adjust text appearance, alignment, and output settings when integrating barcodes into UI or print workflows. +// Prompt: Create a GS1 Code 128 barcode, apply a custom font for human‑readable text, and save as PNG. +// Tags: gs1,code128,barcode,generation,font,png,aspose.barcode + using System; -using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 Code 128 barcode and saving it as a PNG file. +/// Example program that generates a GS1 Code 128 barcode, +/// applies a custom font to the human‑readable text, and saves it as a PNG file. /// class Program { /// /// Entry point of the application. - /// Generates a GS1 Code 128 barcode with custom font settings and writes it to disk. /// static void Main() { - // Define the GS1 Code 128 data (Application Identifier 01 for GTIN) - string codeText = "(01)12345678901231"; - - // Build the full output file path in the current directory - string outputPath = Path.Combine(Environment.CurrentDirectory, "gs1code128.png"); - - // Initialize the barcode generator for GS1 Code 128 with the specified data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + // Initialize the barcode generator with GS1 Code 128 symbology and sample GS1 data. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) { - // Set a custom font (Arial, 12pt) for the human‑readable text below the barcode + // Set a custom font (Arial, 12pt) for the human‑readable text displayed below the barcode. generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; - // Ensure the human‑readable text appears below the barcode (default behavior) - generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + // Align the human‑readable text to the center of the barcode. + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; - // Save the generated barcode image as a PNG file to the specified path - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the generated barcode image to a PNG file. + generator.Save("gs1code128.png"); } - // Inform the user where the barcode image has been saved - Console.WriteLine($"GS1 Code 128 barcode saved to: {outputPath}"); + // Inform the user that the barcode has been created successfully. + Console.WriteLine("GS1 Code 128 barcode generated and saved as gs1code128.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs b/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs index 6cbb646..df332e8 100644 --- a/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs +++ b/gs1-barcode-types/create-gs1-code-128-barcode-rotate-image-90-degrees-clockwise-and-store-as-bmp.cs @@ -1,35 +1,34 @@ +// Title: Create and rotate a GS1 Code 128 barcode saved as BMP +// Description: Demonstrates generating a GS1 Code 128 barcode, rotating the image 90° clockwise, and saving it in BMP format. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. It illustrates typical tasks such as setting rotation angles and exporting to bitmap images, which developers often need when integrating barcodes into documents or printing workflows. +// Prompt: Create a GS1 Code 128 barcode, rotate the image 90 degrees clockwise, and store as BMP. +// Tags: gs1, code128, barcode, generation, rotation, bmp, aspose.barcode + using System; -using Aspose.BarCode.Generation; using Aspose.BarCode; +using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 Code 128 barcode and saving it as a BMP image. +/// Example program that generates a GS1 Code 128 barcode, rotates it, and saves as BMP. /// class Program { /// - /// Entry point of the application. Generates a barcode, rotates it, and saves the image. + /// Entry point of the application. /// static void Main() { - // Define the barcode text. For GS1 Code 128, AI (Application Identifier) values must be enclosed in parentheses. - string codeText = "(01)12345678901231"; + // Define sample GS1 Code 128 data (Application Identifier 01 - GTIN) + const string codeText = "(01)12345678901231"; - // Specify the output file path where the BMP image will be saved. - string outputPath = "gs1code128.bmp"; - - // Initialize the barcode generator with the desired encoding type and text. - // The 'using' statement ensures the generator is properly disposed after use. + // Initialize the barcode generator with GS1 Code 128 symbology and the data using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Set the rotation angle to 90 degrees clockwise. + // Set rotation angle to 90 degrees clockwise generator.Parameters.RotationAngle = 90f; - // Save the generated barcode image to the specified path in BMP format. - generator.Save(outputPath, BarCodeImageFormat.Bmp); + // Save the generated barcode image as a BMP file + generator.Save("gs1code128.bmp"); } - - // Inform the user that the barcode image has been saved. - Console.WriteLine($"Barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs index ef9393c..d6048b5 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-apply-grayscale-filter-and-save-result-as-tiff-image.cs @@ -1,3 +1,9 @@ +// Title: Create GS1 DataMatrix barcode with grayscale filter and save as TIFF +// Description: Demonstrates generating a GS1 DataMatrix barcode, converting it to grayscale, and saving the result as a TIFF image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image processing category. It showcases the use of BarcodeGenerator for GS1 DataMatrix symbology, Aspose.Drawing for bitmap manipulation, and applying a grayscale ColorMatrix via ImageAttributes. Developers often need to customize barcode appearance, apply filters, and export to various image formats such as TIFF for printing or archival purposes. +// Prompt: Create a GS1 DataMatrix barcode, apply a grayscale filter, and save the result as a TIFF image. +// Tags: gs1datamatrix, barcode, grayscale, tiff, imageprocessing, aspose.barcode, aspose.drawing + using System; using System.IO; using Aspose.BarCode; @@ -6,57 +12,61 @@ using Aspose.Drawing.Imaging; /// -/// Demonstrates generation of a GS1 DataMatrix barcode and conversion to a grayscale TIFF image. +/// Program demonstrating GS1 DataMatrix barcode generation, grayscale conversion, and TIFF output. /// class Program { /// - /// Entry point of the application. - /// Generates a GS1 DataMatrix barcode, converts it to grayscale, and saves it as a TIFF file. + /// Entry point. Generates the barcode, applies grayscale filter, and saves as TIFF. /// static void Main() { - // Define the barcode text using AI (01) for GTIN. - string codeText = "(01)12345678901231"; - - // Determine the output file path in the current working directory. - string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "gs1datamatrix.tiff"); + // Define the output file path for the TIFF image + string outputPath = "gs1datamatrix.tiff"; - // Initialize the barcode generator for GS1 DataMatrix with the specified text. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) + // Initialize a barcode generator for GS1 DataMatrix with sample GS1 data + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, "(01)12345678901231")) { - // Generate the original colored bitmap. - using (Bitmap original = generator.GenerateBarCodeImage()) + // Generate the barcode as a bitmap image + using (Bitmap originalBitmap = generator.GenerateBarCodeImage()) { - // Create a new bitmap with the same dimensions to hold the grayscale image. - using (Bitmap grayBitmap = new Bitmap(original.Width, original.Height)) + // Create a new bitmap to hold the grayscale version + using (Bitmap grayBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height)) { - // Iterate over each pixel to compute its grayscale value. - for (int y = 0; y < original.Height; y++) + // Obtain a graphics object for drawing onto the grayscale bitmap + using (Graphics graphics = Graphics.FromImage(grayBitmap)) { - for (int x = 0; x < original.Width; x++) + // Define a grayscale color matrix (luminosity method) + var grayMatrix = new ColorMatrix(new float[][] { - // Retrieve the original pixel color. - Color pixelColor = original.GetPixel(x, y); - - // Compute luminance using the simple average method. - int gray = (pixelColor.R + pixelColor.G + pixelColor.B) / 3; + new float[] { 0.3f, 0.3f, 0.3f, 0, 0 }, + new float[] { 0.59f, 0.59f, 0.59f, 0, 0 }, + new float[] { 0.11f, 0.11f, 0.11f, 0, 0 }, + new float[] { 0, 0, 0, 1, 0 }, + new float[] { 0, 0, 0, 0, 1 } + }); - // Preserve the original alpha channel while setting RGB to the grayscale value. - Color grayColor = Color.FromArgb(pixelColor.A, gray, gray, gray); - - // Assign the grayscale color to the new bitmap. - grayBitmap.SetPixel(x, y, grayColor); + // Apply the grayscale matrix using ImageAttributes + using (ImageAttributes attributes = new ImageAttributes()) + { + attributes.SetColorMatrix(grayMatrix); + // Draw the original bitmap onto the grayscale bitmap using the color matrix + graphics.DrawImage( + originalBitmap, + new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height), + 0, 0, originalBitmap.Width, originalBitmap.Height, + GraphicsUnit.Pixel, + attributes); } } - // Save the grayscale bitmap as a TIFF file at the specified path. + // Save the resulting grayscale bitmap as a TIFF file grayBitmap.Save(outputPath, ImageFormat.Tiff); } } } - // Inform the user where the TIFF file has been saved. - Console.WriteLine($"GS1 DataMatrix barcode saved as TIFF at: {outputPath}"); + // Output the full path of the saved barcode image + Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs index 8996544..bc5502e 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-set-background-transparency-and-export-as-png-with-alpha-channel.cs @@ -1,38 +1,35 @@ +// Title: Create GS1 DataMatrix barcode with transparent background and PNG output +// Description: Demonstrates generating a GS1 DataMatrix barcode, applying a fully transparent background, and saving it as a PNG that retains the alpha channel. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and drawing parameters to control visual appearance, a common requirement when integrating barcodes into UI designs that need transparent backgrounds. +// Prompt: Create a GS1 DataMatrix barcode, set background transparency, and export as PNG with an alpha channel. +// Tags: gs1 datamatrix, background transparency, png, aspose.barcode, barcode generation + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; /// -/// Demonstrates generating a GS1 DataMatrix barcode with a transparent background -/// and saving it as a PNG file using Aspose.BarCode. +/// Demonstrates creating a GS1 DataMatrix barcode with a transparent background and exporting it as a PNG image. /// class Program { /// - /// Entry point of the application. - /// Generates a GS1 DataMatrix barcode, configures a transparent background, - /// saves the image as PNG, and writes a confirmation to the console. + /// Entry point of the example. Generates the barcode, sets transparency, and saves the image. /// static void Main() { - // Define the barcode text: AI 01 (GTIN) followed by a 14‑digit value. - string codeText = "(01)12345678901231"; + // Define the GS1 DataMatrix code text (Application Identifier (01) for GTIN) + string codeText = "(01)01234567890123"; - // Initialize the barcode generator for GS1 DataMatrix with the specified text. + // Initialize the barcode generator for GS1 DataMatrix with the specified text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Configure the barcode's background to be fully transparent. - generator.Parameters.BackColor = Color.Transparent; - - // Define the output file path for the PNG image. - string outputPath = "gs1datamatrix.png"; + // Configure the background color to be fully transparent (alpha = 0) + generator.Parameters.BackColor = Color.FromArgb(0, 255, 255, 255); - // Save the barcode image as PNG; transparency is preserved via the alpha channel. - generator.Save(outputPath, BarCodeImageFormat.Png); + // Save the barcode as a PNG file; the alpha channel preserves transparency + generator.Save("gs1_datamatrix.png"); } - - // Inform the user that the barcode image has been saved. - Console.WriteLine("GS1 DataMatrix barcode saved to gs1datamatrix.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs index 705f2d0..c04e3a8 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-square-shape-and-export-as-high-resolution-tiff-for-printing.cs @@ -1,36 +1,47 @@ +// Title: Generate GS1 DataMatrix Barcode and Export as High‑Resolution TIFF +// Description: Demonstrates creating a GS1 DataMatrix barcode with a square shape and saving it as a 300 DPI TIFF image for printing. +// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and DataMatrixVersion classes to produce print‑ready barcodes. Developers often need to control barcode dimensions, resolution, and output format for high‑quality print media, making this a typical use case for Aspose.BarCode. +// Prompt: Create a GS1 DataMatrix barcode, specify square shape, and export as high‑resolution TIFF for printing. +// Tags: gs1, datamatrix, barcode, generation, tiff, high-resolution, printing, aspose.barcode, aspose.drawing + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; /// -/// Demonstrates generation of a GS1 DataMatrix barcode and saves it as a TIFF image. +/// Example program that generates a GS1 DataMatrix barcode, +/// configures it as a square symbol, and saves it as a high‑resolution TIFF file. /// class Program { /// - /// Entry point of the application. Generates a GS1 DataMatrix barcode with a sample GTIN and writes it to a file. + /// Entry point of the example. Creates the barcode, sets printing‑ready parameters, + /// and writes the result to disk. /// static void Main() { - // Sample GS1 DataMatrix code text (GTIN with AI (01)) - string codeText = "(01)12345678901231"; + // Sample GS1 DataMatrix code text (Application Identifier 01 and 10) + string codeText = "(01)12345678901231(10)ABC123"; - // Create the barcode generator for GS1 DataMatrix using the specified code text + // Initialize the barcode generator for GS1 DataMatrix with the provided text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Ensure a square DataMatrix by selecting a square version (20x20 modules) + // Set high resolution (300 DPI) suitable for printing + generator.Parameters.Resolution = 300f; + + // Configure DataMatrix to be square by selecting a square ECC200 version generator.Parameters.Barcode.DataMatrix.DataMatrixVersion = DataMatrixVersion.ECC200_20x20; - // Force the aspect ratio to 1:1 for a perfect square generator.Parameters.Barcode.DataMatrix.AspectRatio = 1f; - // Set a high resolution (e.g., 300 DPI) suitable for printing - generator.Parameters.Resolution = 300f; + // Optional: define foreground (barcode) and background colors + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; - // Save the generated barcode as a high‑resolution TIFF image - generator.Save("GS1DataMatrix.tiff"); + // Save the barcode as a high‑resolution TIFF image + generator.Save("gs1_datamatrix.tiff"); } - // Inform the user that the barcode has been generated and saved - Console.WriteLine("GS1 DataMatrix barcode generated and saved as GS1DataMatrix.tiff"); + Console.WriteLine("GS1 DataMatrix barcode generated successfully."); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs index ad5f8ac..98f82bf 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-specify-utf-8-encoding-mode-and-export-to-jpeg-with-quality-90.cs @@ -1,40 +1,41 @@ +// Title: Generate GS1 DataMatrix barcode and save as JPEG with UTF‑8 encoding +// Description: Demonstrates creating a GS1 DataMatrix barcode, setting UTF‑8 ECI encoding, and exporting it to a JPEG image. +// Category-Description: This example is part of the Aspose.BarCode generation collection, showing how to configure a specific symbology (GS1 DataMatrix), apply character set encoding (UTF‑8 via ECI), and output the result as a high‑quality JPEG. It utilizes the BarcodeGenerator, EncodeTypes, and BarCodeImageFormat classes—common tools for developers who need to produce product identification codes and integrate them into imaging workflows. +// Prompt: Create a GS1 DataMatrix barcode, specify UTF‑8 encoding mode, and export to JPEG with quality 90. +// Tags: gs1datamatrix, barcode, generation, jpeg, eci, utf-8, aspose.barcode, encodetypes, imageexport + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a GS1 DataMatrix barcode and saving it as a JPEG image using Aspose.BarCode. +/// Example program that generates a GS1 DataMatrix barcode, +/// applies UTF‑8 ECI encoding, and saves it as a JPEG image. /// class Program { /// - /// Entry point of the application. - /// Generates a GS1 DataMatrix barcode with a sample GTIN and writes it to a JPEG file. + /// Entry point of the example. Creates the barcode and writes the image file. /// static void Main() { - // Sample GS1 DataMatrix code text (GTIN with Application Identifier 01) - const string codeText = "(01)01234567890128"; - - // Destination file path for the generated JPEG image + // Output file name for the generated JPEG image const string outputPath = "gs1datamatrix.jpg"; - // Initialize the barcode generator for GS1 DataMatrix with the specified payload - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) + // GS1 DataMatrix payload (Application Identifier 01 with a 14‑digit GTIN) + const string codeText = "(01)12345678901231"; + + // Initialize the barcode generator for GS1 DataMatrix symbology + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix)) { - // Set the ECI (Extended Channel Interpretation) to UTF‑8 for proper encoding of the payload + // Assign the code text to be encoded + generator.CodeText = codeText; + + // Set the ECI (Extended Channel Interpretation) to UTF‑8 for proper character encoding generator.Parameters.Barcode.DataMatrix.ECIEncoding = ECIEncodings.UTF8; - // Save the generated barcode as a JPEG image. - // Aspose.BarCode does not provide a direct JPEG quality parameter, - // so the library's default quality setting is used. + // Save the barcode as a JPEG image (default quality; Aspose uses 90 if not specified) generator.Save(outputPath, BarCodeImageFormat.Jpeg); } - - // Inform the user that the barcode image has been saved - Console.WriteLine($"GS1 DataMatrix barcode saved to '{outputPath}'."); - // Note about JPEG quality limitation - Console.WriteLine("Note: JPEG quality cannot be set explicitly via Aspose.BarCode API."); } } \ No newline at end of file diff --git a/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs b/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs index 85467d8..c33555d 100644 --- a/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs +++ b/gs1-barcode-types/create-gs1-datamatrix-barcode-using-multiple-application-identifiers-and-export-to-jpeg-format.cs @@ -1,28 +1,35 @@ +// Title: Generate GS1 DataMatrix Barcode with Multiple Application Identifiers and Save as JPEG +// Description: Demonstrates creating a GS1 DataMatrix barcode that encodes several Application Identifiers (GTIN, batch number, expiration date) and exporting the image to JPEG. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. Developers often need to embed GS1 data in DataMatrix symbols for supply‑chain labeling, requiring multiple Application Identifiers. The snippet shows typical steps: define GS1‑formatted text, instantiate the generator, and save the result in a common image format. +// Prompt: Create a GS1 DataMatrix barcode using multiple Application Identifiers and export to a JPEG format. +// Tags: gs1, datamatrix, barcode, generation, jpeg, aspose.barcode + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 DataMatrix barcode using Aspose.BarCode. +/// Example program that creates a GS1 DataMatrix barcode containing several Application Identifiers +/// and saves the generated image as a JPEG file. /// class Program { /// - /// Entry point of the application. Generates a GS1 DataMatrix barcode with sample data and saves it as a JPEG file. + /// Entry point of the example. Generates the barcode and writes the output file path to the console. /// static void Main() { - // Define the GS1 DataMatrix payload containing multiple Application Identifiers (AIs): + // Define GS1 DataMatrix code text with multiple Application Identifiers (AIs): // (01) – GTIN, (10) – Batch/Lot number, (17) – Expiration date (YYMMDD) - string codeText = "(01)12345678901231(10)BATCH123(17)250731"; + string codeText = "(01)12345678901231(10)ABC123(17)240731"; - // Destination file path for the generated barcode image (JPEG format) + // Specify the output file path for the JPEG image string outputPath = "gs1_datamatrix.jpg"; - // Initialize the barcode generator for GS1 DataMatrix symbology with the specified payload + // Create the barcode generator for GS1 DataMatrix using the defined code text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Persist the generated barcode to the file system as a JPEG image + // Save the generated barcode image as a JPEG file generator.Save(outputPath, BarCodeImageFormat.Jpeg); } diff --git a/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs b/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs index a0da7f9..cd80b78 100644 --- a/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs +++ b/gs1-barcode-types/create-upc-barcode-with-databar-coupon-then-overlay-qr-code-using-graphics-library.cs @@ -1,3 +1,9 @@ +// Title: Create UPC‑A barcode with DataBar coupon and overlay QR code +// Description: Demonstrates generating a UPC‑A barcode with a GS1 DataBar coupon and then compositing a QR code on top using Aspose.Drawing. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image composition category. It shows how to use BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon and EncodeTypes.QR, configure parameters, and combine images via Aspose.Drawing. Developers often need to create composite barcode images for packaging, marketing, or inventory applications, and this snippet illustrates the typical workflow. +// Prompt: Create a UPC‑A barcode with a DataBar coupon, then overlay a QR code using a graphics library. +// Tags: upc barcode, databar coupon, qr code, image overlay, aspose.barcode, aspose.drawing, png output + using System; using System.IO; using Aspose.BarCode; @@ -6,71 +12,82 @@ using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a UPC‑A barcode with a DataBar coupon and overlaying a QR code. +/// Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon and overlaying a QR code. /// class Program { /// - /// Application entry point. + /// Entry point. Generates the barcode images, composes them, and saves the result. /// static void Main() { - // Define the UPC‑A barcode text, including the DataBar coupon segment. - const string upcCodeText = "012345678905(8110)106141416543213500110000310123196000"; + // Define file names for the individual and combined images + string upcFile = "upc_databar.png"; + string combinedFile = "combined.png"; + + // ----------------------------------------------------------------- + // 1. Create UPC‑A barcode with a GS1 DataBar coupon + // ----------------------------------------------------------------- + // Sample codetext: UPCA part + DataBar part + string upcCodeText = "514141100906(8110)106141416543213500110000310123196000"; - // Create a barcode generator for UPC‑A with GS1 DataBar coupon encoding. using (var upcGenerator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, upcCodeText)) { - // Set a high resolution to improve image quality. - upcGenerator.Parameters.Resolution = 300f; + // Optional: set image size (auto‑size mode) + upcGenerator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + upcGenerator.Parameters.ImageWidth.Point = 400f; + upcGenerator.Parameters.ImageHeight.Point = 200f; - // Render the UPC‑A barcode to a memory stream. - using (var upcStream = new MemoryStream()) - { - upcGenerator.Save(upcStream, BarCodeImageFormat.Png); - upcStream.Position = 0; // Reset stream position for reading. + // Save the UPC‑A barcode image to file + upcGenerator.Save(upcFile); + } - // Load the generated barcode into a bitmap. - using (var upcBitmap = new Bitmap(upcStream)) - { - // Define the QR code text (e.g., a URL). - const string qrCodeText = "https://example.com"; + // ----------------------------------------------------------------- + // 2. Create a QR code that will be overlaid on the UPC image + // ----------------------------------------------------------------- + string qrCodeText = "https://example.com"; - // Create a barcode generator for a QR code. - using (var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, qrCodeText)) - { - // Use the same high resolution for consistency. - qrGenerator.Parameters.Resolution = 300f; + using (var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, qrCodeText)) + { + // Set high error correction level for better readability after overlay + qrGenerator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH; - // Render the QR code to a memory stream. - using (var qrStream = new MemoryStream()) - { - qrGenerator.Save(qrStream, BarCodeImageFormat.Png); - qrStream.Position = 0; // Reset stream position for reading. + // Define QR image size (auto‑size mode) + qrGenerator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; + qrGenerator.Parameters.ImageWidth.Point = 150f; + qrGenerator.Parameters.ImageHeight.Point = 150f; - // Load the QR code into a bitmap. - using (var qrBitmap = new Bitmap(qrStream)) - { - // Prepare to draw the QR code onto the UPC‑A bitmap. - using (var graphics = Graphics.FromImage(upcBitmap)) - { - // Calculate position: bottom‑right corner with a small margin. - int margin = 10; - int x = upcBitmap.Width - qrBitmap.Width - margin; - int y = upcBitmap.Height - qrBitmap.Height - margin; + // Generate QR bitmap in memory + using (Bitmap qrBitmap = qrGenerator.GenerateBarCodeImage()) + { + // ----------------------------------------------------------------- + // 3. Load the UPC image and overlay the QR code onto it + // ----------------------------------------------------------------- + if (!File.Exists(upcFile)) + { + Console.WriteLine($"Error: UPC image file '{upcFile}' not found."); + return; + } - // Draw the QR code onto the UPC‑A image. - graphics.DrawImage(qrBitmap, x, y, qrBitmap.Width, qrBitmap.Height); - } + using (Bitmap upcBitmap = new Bitmap(upcFile)) + { + // Determine position: bottom‑right corner with a 10‑pixel margin + int margin = 10; + int x = upcBitmap.Width - qrBitmap.Width - margin; + int y = upcBitmap.Height - qrBitmap.Height - margin; - // Save the combined image to disk. - upcBitmap.Save("CombinedBarcode.png", ImageFormat.Png); - Console.WriteLine("Combined barcode saved as CombinedBarcode.png"); - } - } + // Draw the QR code onto the UPC image + using (Graphics graphics = Graphics.FromImage(upcBitmap)) + { + graphics.DrawImage(qrBitmap, new Rectangle(x, y, qrBitmap.Width, qrBitmap.Height)); } + + // Save the combined image to file + upcBitmap.Save(combinedFile, ImageFormat.Png); } } } + + Console.WriteLine($"Combined barcode image saved as '{combinedFile}'."); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs index 4a3f7d6..8946117 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-custom-human-readable-text-below-and-save-as-jpeg.cs @@ -1,34 +1,46 @@ +// Title: Generate GS1 Code 128 barcode with custom human‑readable text +// Description: Demonstrates creating a GS1 Code 128 barcode, adding centered human‑readable text below, and saving it as a JPEG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.GS1Code128, configure CodeTextParameters, and apply AutoSizeMode. Developers often need to produce GS1‑compliant barcodes for product identification, customize human‑readable text appearance, and export to common image formats like JPEG. +// Prompt: Generate a GS1 Code 128 barcode, embed custom human‑readable text below, and save as JPEG. +// Tags: gs1, code128, barcode, generation, human‑readable, jpeg, aspose.barcode + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 Code128 barcode and saving it as a JPEG image. +/// Program demonstrating GS1 Code 128 barcode generation with custom human‑readable text. /// class Program { /// - /// Entry point of the application. Generates a barcode and writes the output path to the console. + /// Entry point. Generates the barcode, configures text, and saves as JPEG. /// static void Main() { - // Output file name for the generated barcode image - const string outputPath = "gs1code128.jpg"; - - // The data to encode; GS1 format with Application Identifier (01) for GTIN - const string codeText = "(01)12345678901231"; + // Define GS1 Code 128 data: (01) – GTIN, (21) – Serial Number + const string gs1Data = "(01)12345678901231(21)ABC123"; - // Initialize a barcode generator for GS1 Code128 with the specified text - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + // Initialize the barcode generator for GS1 Code 128 with the specified data + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Data)) { - // Configure the human‑readable text to appear below the barcode graphic + // Position human‑readable text below the barcode and center it horizontally generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; + generator.Parameters.Barcode.CodeTextParameters.Alignment = TextAlignment.Center; + + // Set the font family and size for the human‑readable text + generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"; + generator.Parameters.Barcode.CodeTextParameters.Font.Size.Point = 12f; + + // Enable automatic sizing using interpolation (no explicit bar height required) + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - // Persist the generated barcode to a JPEG file at the specified path + // Define output file path and save the barcode as a JPEG image + const string outputPath = "gs1_code128.jpg"; generator.Save(outputPath, BarCodeImageFormat.Jpeg); } - // Inform the user where the barcode image was saved - Console.WriteLine($"Barcode saved to {outputPath}"); + // Inform the user that the barcode has been saved + Console.WriteLine("GS1 Code 128 barcode saved successfully."); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs index ea0f2e9..b801a8e 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-embed-it-in-pdf-document-and-save-pdf.cs @@ -1,61 +1,60 @@ +// Title: Generate GS1 Code 128 Barcode and Embed in PDF +// Description: Demonstrates how to create a GS1 Code 128 barcode, place it into a PDF document, and save the result. +// Category-Description: This example belongs to the Aspose.BarCode PDF integration category, showcasing the use of BarcodeGenerator (Aspose.BarCode.Generation) to produce a barcode image and Aspose.Pdf (Document, Image) to embed that image into a PDF. Typical scenarios include generating product labels, shipping documents, or any printable material that requires a GS1-compliant barcode. +// Prompt: Generate a GS1 Code 128 barcode, embed it in a PDF document, and save the PDF. +// Tags: gs1 code 128, barcode generation, pdf output, aspose.barcode, aspose.pdf + using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Pdf; -using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a GS1 Code 128 barcode and embedding it into a PDF using Aspose libraries. +/// Example program that creates a GS1 Code 128 barcode, inserts it into a PDF, and saves the file. /// class Program { /// - /// Application entry point. Generates a barcode, inserts it into a PDF, and saves the file. + /// Entry point of the application. /// static void Main() { - // Define the output PDF file name. - const string outputPdfPath = "GS1Code128.pdf"; - - // Barcode content: GS1 Code 128 with GTIN example. - const string barcodeText = "(01)12345678901231"; + // Define the output PDF file name + const string pdfPath = "GS1Code128.pdf"; - // Initialize the barcode generator for GS1 Code 128. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, barcodeText)) + // Initialize a barcode generator for GS1 Code 128 with sample AI code text + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) { - // Render the barcode to a memory stream in PNG format. + // Render the barcode to a memory stream in PNG format using (var barcodeStream = new MemoryStream()) { generator.Save(barcodeStream, BarCodeImageFormat.Png); - // Reset stream position to the beginning for reading. + // Reset stream position to the beginning for reading barcodeStream.Position = 0; - // Create a new PDF document. + // Create a new PDF document using (var pdfDoc = new Document()) { - // Add a blank page to the document. + // Add a new page to the PDF var page = pdfDoc.Pages.Add(); - // Create an image object that uses the barcode stream. - var pdfImage = new Aspose.Pdf.Image + // Create an image object from the barcode stream + var image = new Image { ImageStream = barcodeStream - // Optional: set fixed dimensions (points) if needed. - // FixWidth = 200.0, - // FixHeight = 100.0 }; - // Insert the image into the page's paragraph collection. - page.Paragraphs.Add(pdfImage); + // Insert the barcode image into the page's paragraph collection + page.Paragraphs.Add(image); - // Save the PDF to the specified file path. - pdfDoc.Save(outputPdfPath); + // Save the PDF document to the specified path + pdfDoc.Save(pdfPath); } } } - // Inform the user that the PDF has been created. - Console.WriteLine($"PDF with GS1 Code 128 barcode saved to: {outputPdfPath}"); + // Inform the user that the PDF has been saved + Console.WriteLine($"PDF with GS1 Code 128 barcode saved to '{pdfPath}'."); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs b/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs index 7f3127f..a5cf97e 100644 --- a/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs +++ b/gs1-barcode-types/generate-gs1-code-128-barcode-with-ai-data-and-save-as-png-image-file.cs @@ -1,36 +1,37 @@ +// Title: Generate GS1 Code 128 Barcode with AI Data and Save as PNG +// Description: Creates a GS1‑compliant Code 128 barcode containing Application Identifier data and writes it to a PNG file. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, demonstrating how to encode GS1 Application Identifier (AI) data using the BarcodeGenerator and EncodeTypes classes. Developers often need to create GS1‑compliant barcodes for product identification, inventory, and logistics, requiring correct AI formatting and optional checksum display. The snippet shows the essential steps to configure parameters and save the barcode as an image. +// Prompt: Generate a GS1 Code 128 barcode with AI data and save as a PNG image file. +// Tags: gs1,code128,barcode,generation,png,aspose.barcode,applicationidentifier + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 Code 128 barcode using Aspose.BarCode. +/// Demonstrates generation of a GS1 Code 128 barcode with AI data and saving it as a PNG image. /// class Program { /// - /// Entry point of the application. Generates a GS1 Code 128 barcode with sample AI data - /// and saves it as a PNG file. + /// Entry point of the example. Generates the barcode and writes it to disk. /// static void Main() { - // Define the output file name for the generated barcode image. - string outputPath = "gs1code128.png"; - - // Sample GS1 Application Identifier (AI) data: - // (01) – GTIN, (10) – Batch/Lot number. - string codeText = "(01)12345678901231(10)BATCH123"; + // Define GS1 AI data: (01) – GTIN, (21) – Serial number + string codeText = "(01)01234567890123(21)ABC123"; - // Initialize the barcode generator for GS1 Code 128 with the provided AI data. + // Initialize the barcode generator with GS1 Code 128 symbology and the AI data using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) { - // Ensure the checksum digit is displayed in the human‑readable text. + // Optional: display the checksum in the human‑readable text generator.Parameters.Barcode.ChecksumAlwaysShow = true; - // Save the generated barcode image to the specified path in PNG format. - generator.Save(outputPath); + // Save the generated barcode as a PNG image file + generator.Save("gs1code128.png"); } - // Inform the user where the barcode image has been saved. - Console.WriteLine($"GS1 Code 128 barcode saved to: {outputPath}"); + // Inform the user that the barcode has been saved + Console.WriteLine("GS1 Code 128 barcode saved as gs1code128.png"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs index fbb56af..68f2151 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-retrieve-its-byte-array-and-send-it-via-http-response.cs @@ -1,55 +1,56 @@ +// Title: Generate GS1 DataMatrix Barcode and Retrieve Byte Array +// Description: This example creates a GS1 DataMatrix barcode, extracts its PNG byte array, and demonstrates how it could be sent in an HTTP response. +// Category-Description: Aspose.BarCode barcode generation examples that illustrate creating various symbologies, configuring image parameters, and obtaining raw image data. Developers often need to generate barcodes on the fly for web APIs, embed them in documents, or transmit them over HTTP. This snippet showcases the BarcodeGenerator class, image format handling, and byte array extraction, which are common tasks in e‑commerce, logistics, and inventory systems. +// Prompt: Generate a GS1 DataMatrix barcode, retrieve its byte array, and send it via HTTP response. +// Tags: gs1, datamatrix, barcode, generation, bytearray, http response, aspose.barcode, aspnet + using System; using System.IO; -using System.Net; -using System.Net.Http; +using System.Text; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a GS1 DataMatrix barcode using Aspose.BarCode, -/// converting it to PNG, and simulating an HTTP response containing the image. +/// Demonstrates how to generate a GS1 DataMatrix barcode, obtain its PNG byte array, +/// and illustrate the data that would be sent in an HTTP response. /// -public class Program +class Program { /// - /// Entry point of the application. - /// Generates a barcode, writes it to a memory stream, and creates an HttpResponseMessage. + /// Entry point of the console application. + /// Generates the barcode, extracts the byte array, and prints a Base64 representation. /// - public static void Main() + static void Main() { - // Define the GS1 DataMatrix payload (GTIN example) - const string codeText = "(01)12345678901231"; + // NOTE: The snippet runner is a console application and cannot host an HTTP server. + // Therefore, the barcode byte array is generated and printed as a Base64 string, + // which represents the data that would be sent in an HTTP response. + + // Define a sample GS1 Application Identifier (AI) payload for the barcode. + const string gs1CodeText = "(01)12345678901231"; - // Initialize the barcode generator with GS1 DataMatrix encoding and the payload - using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) + // Initialize the barcode generator for the GS1 DataMatrix symbology. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, gs1CodeText)) { - // Set the image resolution to 300 DPI (optional) - generator.Parameters.Resolution = 300f; + // Optional: adjust image dimensions and resolution to meet specific requirements. + generator.Parameters.ImageWidth.Point = 300f; + generator.Parameters.ImageHeight.Point = 300f; + generator.Parameters.Resolution = 96; - // Create a memory stream to hold the generated PNG image + // Generate the barcode image and write it into a memory stream. using (var ms = new MemoryStream()) { - // Save the barcode image into the memory stream in PNG format generator.Save(ms, BarCodeImageFormat.Png); - // Retrieve the raw byte array of the PNG image - byte[] barcodeBytes = ms.ToArray(); - - // Simulate sending the image as an HTTP response - using (var response = new HttpResponseMessage(HttpStatusCode.OK)) - { - // Attach the image bytes as the response content - response.Content = new ByteArrayContent(barcodeBytes); - // Set the appropriate MIME type for PNG images - response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png"); + byte[] barcodeBytes = ms.ToArray(); // Retrieve the raw PNG byte array. - // Output response details for demonstration purposes - Console.WriteLine($"HTTP Status: {response.StatusCode}"); - Console.WriteLine($"Content Length: {barcodeBytes.Length} bytes"); + // Output the length of the generated byte array for verification. + Console.WriteLine($"Generated barcode byte array length: {barcodeBytes.Length}"); - // Show a snippet of the Base64 representation of the image - string base64 = Convert.ToBase64String(barcodeBytes); - Console.WriteLine($"Base64 (first 100 chars): {base64.Substring(0, Math.Min(100, base64.Length))}..."); - } + // Convert the byte array to a Base64 string to simulate an HTTP response body. + string base64 = Convert.ToBase64String(barcodeBytes); + Console.WriteLine("Base64-encoded PNG barcode:"); + Console.WriteLine(base64); } } } diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs index 32d65ce..9631dfa 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-set-module-size-to-5-pixels-and-export-as-bmp.cs @@ -1,34 +1,35 @@ +// Title: Generate GS1 DataMatrix barcode with custom module size and BMP output +// Description: Demonstrates creating a GS1 DataMatrix barcode, setting its module size to 5 pixels, and saving it as a BMP image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1DataMatrix. Typical use cases include encoding product identifiers (GTIN) and lot numbers for supply‑chain labeling, where developers need to control visual parameters like X‑dimension and export to raster formats such as BMP. +// Prompt: Generate a GS1 DataMatrix barcode, set module size to 5 pixels, and export as BMP. +// Tags: gs1datamatrix, barcode generation, module size, bmp, aspose.barcode, csharp + using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; /// -/// Demonstrates generating a GS1 DataMatrix barcode using Aspose.BarCode. +/// Example program that generates a GS1 DataMatrix barcode, +/// configures the module size, and saves the result as a BMP file. /// class Program { /// - /// Entry point of the application. Generates a GS1 DataMatrix barcode and saves it as a BMP file. + /// Entry point of the application. /// static void Main() { - // Define the barcode content: AI (01) followed by a 14‑digit GTIN. - string codeText = "(01)12345678901231"; + // Define the GS1 DataMatrix code text (GTIN and lot number) using Application Identifiers. + const string codeText = "(01)12345678901231(10)LOT123"; - // Choose the GS1 DataMatrix symbology. - BaseEncodeType encodeType = EncodeTypes.GS1DataMatrix; - - // Create a barcode generator with the specified type and content. - using (var generator = new BarcodeGenerator(encodeType, codeText)) + // Initialize the barcode generator for GS1 DataMatrix with the specified code text. + using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Configure the X‑dimension (module size) to 5 pixels. + // Set the module (X‑dimension) size to 5 pixels to control barcode density. generator.Parameters.Barcode.XDimension.Pixels = 5f; - // Render and save the barcode as a BMP image. + // Save the generated barcode image as a BMP file. generator.Save("gs1datamatrix.bmp"); } - - // Inform the user that the image has been saved. - Console.WriteLine("GS1 DataMatrix barcode saved as gs1datamatrix.bmp"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs b/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs index 97bc9af..f9b2e97 100644 --- a/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs +++ b/gs1-barcode-types/generate-gs1-datamatrix-barcode-with-error-correction-level-200-and-export-as-png.cs @@ -1,38 +1,41 @@ +// Title: Generate GS1 DataMatrix barcode with ECC200 and save as PNG +// Description: Demonstrates creating a GS1 DataMatrix barcode using Aspose.BarCode, setting error correction level ECC200, and exporting the image as a PNG file. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on GS1 DataMatrix symbology. It showcases the use of BarcodeGenerator, EncodeTypes, and DataMatrixEccType to configure error correction and save the result. Developers often need to generate GS1-compliant DataMatrix codes for product identification and require control over ECC levels for reliability. +// Prompt: Generate a GS1 DataMatrix barcode with error correction level 200 and export as PNG. +// Tags: gs1datamatrix, barcode generation, error correction, png, aspose.barcode + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 DataMatrix barcode and saving it as a PNG file. +/// Example program that generates a GS1 DataMatrix barcode with ECC200 error correction +/// and saves it as a PNG image using the Aspose.BarCode library. /// class Program { /// - /// Entry point of the application. Generates a GS1 DataMatrix barcode and writes it to disk. + /// Entry point of the application. /// static void Main() { - // Define the output file path where the barcode image will be saved. - string outputPath = "gs1datamatrix.png"; + // Define the GS1 DataMatrix code text (GTIN) to encode. + const string codeText = "(01)12345678901231"; - // Sample GS1 DataMatrix code text (example with GTIN). - // The parentheses denote Application Identifiers as per GS1 standards. - string codeText = "(01)12345678901231"; + // Specify the output file path for the generated PNG image. + const string outputPath = "gs1datamatrix.png"; - // Create a barcode generator configured for GS1 DataMatrix encoding. + // Initialize the barcode generator for GS1 DataMatrix with the provided text. using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Set the DataMatrix error correction level to ECC200 (standard for GS1 DataMatrix). + // Configure the DataMatrix error correction level to ECC200 (value 200). generator.Parameters.Barcode.DataMatrix.DataMatrixEcc = DataMatrixEccType.Ecc200; - // Optional: set the image resolution to 300 DPI for higher quality output. - generator.Parameters.Resolution = 300f; - - // Save the generated barcode as a PNG image to the specified path. + // Save the generated barcode image to the specified path in PNG format. generator.Save(outputPath, BarCodeImageFormat.Png); } // Inform the user that the barcode has been successfully saved. - Console.WriteLine($"GS1 DataMatrix barcode saved to: {outputPath}"); + Console.WriteLine($"GS1 DataMatrix barcode saved to '{outputPath}'."); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs index 24b400f..e5d1b6b 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-retrieve-image-as-byte-array-and-attach-to-email.cs @@ -1,55 +1,62 @@ +// Title: Generate UPC‑A barcode with Code128 coupon and email attachment +// Description: Demonstrates creating a UPC‑A barcode that includes a Code128 coupon, converting it to a PNG byte array, and attaching it to an email message. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image handling category. It showcases the use of BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon, saving the barcode to a memory stream, and integrating the resulting image into a System.Net.Mail email. Developers often need to generate barcodes on‑the‑fly and embed them in communications such as order confirmations or promotional emails. +// Prompt: Generate a UPC‑A barcode with a Code128 coupon, retrieve image as byte array, and attach to email. +// Tags: upc-a, code128, barcode generation, image byte array, email attachment, aspose.barcode, system.net.mail + using System; using System.IO; +using System.Net; using System.Net.Mail; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a UPC‑A with GS1‑128 coupon barcode, -/// saving it to a PNG image, and attaching it to an email message. +/// Example program that generates a UPC‑A barcode with an embedded Code128 coupon, +/// converts the barcode image to a byte array, and attaches it to an email message. /// class Program { /// /// Entry point of the application. - /// Generates the barcode, writes it to a memory stream, - /// and creates an email with the barcode attached. /// - /// Command‑line arguments (not used). - static void Main(string[] args) + static void Main() { - // Define the barcode text: UPC‑A part, GS1‑128 data in parentheses, and additional data. - string codeText = "514141100906(8102)03"; - - // Initialize the barcode generator for UPC‑A with GS1‑128 coupon encoding. - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) + // Create a UPC‑A barcode that includes a Code128 coupon. + // Example codetext: "514141100906(8102)03" + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, "514141100906(8102)03")) { // Save the generated barcode image to a memory stream in PNG format. - using (var ms = new MemoryStream()) + using (var imageStream = new MemoryStream()) { - generator.Save(ms, BarCodeImageFormat.Png); - byte[] barcodeBytes = ms.ToArray(); // Convert stream to byte array. + generator.Save(imageStream, BarCodeImageFormat.Png); + byte[] imageBytes = imageStream.ToArray(); // Convert stream to byte array. - // Create a memory stream for the attachment using the barcode bytes. - using (var attachmentStream = new MemoryStream(barcodeBytes)) + // Prepare an email message and attach the barcode image. + using (var mailMessage = new MailMessage()) { - // Build the email message. - using (var message = new MailMessage()) - { - // Set sender and recipient addresses. - message.From = new MailAddress("sender@example.com"); - message.To.Add("recipient@example.com"); + mailMessage.From = new MailAddress("sender@example.com"); + mailMessage.To.Add("recipient@example.com"); + mailMessage.Subject = "UPC‑A with Code128 Coupon Barcode"; + mailMessage.Body = "Please find the generated barcode attached."; - // Set email subject and body. - message.Subject = "UPC‑A with Code128 Coupon Barcode"; - message.Body = "Please find the generated barcode attached."; - - // Create the attachment (PNG image) and add it to the message. + // Attach the image using a new memory stream based on the byte array. + using (var attachmentStream = new MemoryStream(imageBytes)) + { var attachment = new Attachment(attachmentStream, "barcode.png", "image/png"); - message.Attachments.Add(attachment); + mailMessage.Attachments.Add(attachment); + + // Send the email using an SMTP client. + // Replace host, port, and credentials with real values when deploying. + using (var smtpClient = new SmtpClient("smtp.example.com")) + { + smtpClient.Port = 25; + // smtpClient.Credentials = new NetworkCredential("username", "password"); + // smtpClient.EnableSsl = true; - // Output the size of the generated barcode image for verification. - Console.WriteLine($"Barcode generated: {barcodeBytes.Length} bytes."); + // Uncomment the line below to actually send the email. + // smtpClient.Send(mailMessage); + } } } } diff --git a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs index c95112c..c52d117 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-code128-coupon-set-supplement-space-to-40-pixels-and-save-as-png.cs @@ -1,34 +1,41 @@ +// Title: Generate UPC‑A barcode with Code128 coupon and supplement space +// Description: Demonstrates creating a UPC‑A barcode that includes a Code128 coupon, configuring the supplement spacing, and saving the result as a PNG image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on combined symbologies such as UPC‑A with GS1‑128 coupons. It showcases the use of BarcodeGenerator, EncodeTypes, and the Coupon settings to customize supplement spacing. Developers often need to generate composite barcodes for retail and promotional applications, adjusting visual parameters before exporting to common image formats. +// Prompt: Generate a UPC‑A barcode with a Code128 coupon, set supplement space to 40 pixels, and save as PNG. +// Tags: upc-a, code128, coupon, supplement-space, png, generation, aspose.barcode, encode-types + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a UPC-A coupon barcode with a supplement space using Aspose.BarCode. +/// Example program that creates a UPC‑A barcode with an embedded Code128 coupon, +/// sets the supplement (coupon) spacing, and saves the image as a PNG file. /// class Program { /// - /// Entry point of the application. Generates and saves a barcode image. + /// Entry point of the application. Generates the barcode and writes it to disk. /// static void Main() { - // The data to encode in the barcode, including the coupon information. - string codeText = "514141100906(8102)03"; + // Define the output file path for the generated PNG image + const string outputPath = "upc_code128_coupon.png"; + + // Sample codetext representing a UPC‑A value with a GS1‑128 coupon segment + const string codeText = "514141100906(8102)03"; - // Initialize the barcode generator with the specific encoding type and data. - using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) + // Initialize the barcode generator with the combined UPC‑A/GS1‑128 coupon symbology + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) { - // Set the supplement space (distance) to 40 points. + // Configure the supplement (coupon) space to 40 pixels generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 40f; - // Define the output file path for the generated barcode image. - string outputPath = "upc_a_coupon.png"; - - // Save the barcode image to the specified path. + // Save the generated barcode image in PNG format to the specified path generator.Save(outputPath); - - // Inform the user where the barcode image was saved. - Console.WriteLine($"Barcode saved to {outputPath}"); } + + // Inform the user that the barcode has been saved successfully + Console.WriteLine($"Barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs b/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs index fd8f4cf..a5f437f 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-databar-coupon-then-combine-it-with-logo-using-systemdrawing-graphics.cs @@ -1,3 +1,9 @@ +// Title: Generate UPC‑A DataBar Coupon barcode with logo overlay +// Description: Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon, then merging it with a simple logo using System.Drawing. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, customize colors, and combine the resulting bitmap with other graphics via Aspose.Drawing. Typical use cases include retail product labeling with promotional coupons and brand logos. Developers often need to create combined images for printing or digital display, making this pattern a common reference. +// Prompt: Generate a UPC‑A barcode with a DataBar coupon, then combine it with a logo using System.Drawing graphics. +// Tags: upc-a, databar, coupon, barcode generation, logo overlay, png, aspose.barcode, aspose.drawing + using System; using System.IO; using Aspose.BarCode; @@ -6,94 +12,89 @@ using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a UPC‑A GS1 DataBar coupon barcode, -/// combining it with a simple logo, and saving both images to disk. +/// Example program that creates a UPC‑A barcode with a GS1 DataBar coupon, +/// generates a simple logo, and combines both images into a single PNG file. /// class Program { /// - /// Entry point of the application. - /// Generates the barcode, creates a combined image with a logo, - /// and writes the results to PNG files. + /// Entry point of the example. Generates the barcode, logo, and combined image, + /// then writes the output file locations to the console. /// static void Main() { - // Sample UPC‑A with DataBar coupon code text (UPCA part + GS1 DataBar part) - const string upcCouponCode = "514141100906(8110)106141416543213500110000310123196000"; - - // Output file paths + // Paths for output images const string barcodePath = "barcode.png"; + const string logoPath = "logo.png"; const string combinedPath = "combined.png"; - // Create a barcode generator for the specified type and data - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, upcCouponCode)) + // ----------------------------------------------------------------- + // 1. Create UPC‑A barcode with a DataBar coupon + // ----------------------------------------------------------------- + // Sample codetext: UPCA part + DataBar part (see EncodeTypes.UpcaGs1DatabarCoupon documentation) + const string couponCodeText = "514141100906(8110)106141416543213500110000310123196000"; + + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, couponCodeText)) { - // Optional: increase resolution for higher quality output - generator.Parameters.Resolution = 300f; + // Optional visual tweaks + generator.Parameters.Barcode.BarColor = Color.Black; + generator.Parameters.BackColor = Color.White; - // Save the generated barcode to a memory stream in PNG format - using (var barcodeStream = new MemoryStream()) + // Generate the barcode image + using (Bitmap barcodeBmp = generator.GenerateBarCodeImage()) { - generator.Save(barcodeStream, BarCodeImageFormat.Png); - barcodeStream.Position = 0; // Reset stream position for reading + // Save the barcode for reference + barcodeBmp.Save(barcodePath, ImageFormat.Png); - // Load the barcode image from the memory stream - using (var barcodeBitmap = new Bitmap(barcodeStream)) + // ----------------------------------------------------------------- + // 2. Create a simple logo image programmatically + // ----------------------------------------------------------------- + using (var logoBmp = new Bitmap(100, 100)) { - // Create a simple 100x100 logo bitmap with the text "Logo" - using (var logoBitmap = new Bitmap(100, 100)) + using (var gLogo = Graphics.FromImage(logoBmp)) { - using (var gLogo = Graphics.FromImage(logoBitmap)) + // Fill background with light gray + gLogo.Clear(Color.LightGray); + using (var font = new Font("Arial", 12f)) { - // Fill background with light gray - gLogo.Clear(Color.LightGray); - - // Draw the word "Logo" centered vertically - using (var font = new Font("Arial", 20f)) - using (var brush = new SolidBrush(Color.Black)) - { - gLogo.DrawString("Logo", font, brush, new PointF(10f, 40f)); - } + // Draw the word "Logo" in the center area + gLogo.DrawString("Logo", font, Brushes.Black, new PointF(10f, 40f)); } + } - // Determine dimensions for the combined image (barcode left, logo right) - int combinedWidth = barcodeBitmap.Width + logoBitmap.Width; - int combinedHeight = Math.Max(barcodeBitmap.Height, logoBitmap.Height); + // Save the logo for reference + logoBmp.Save(logoPath, ImageFormat.Png); - // Create the combined bitmap - using (var combinedBitmap = new Bitmap(combinedWidth, combinedHeight)) - { - using (var g = Graphics.FromImage(combinedBitmap)) - { - // Fill the background with white - g.Clear(Color.White); + // ----------------------------------------------------------------- + // 3. Combine barcode and logo into a single image + // ----------------------------------------------------------------- + int combinedWidth = Math.Max(barcodeBmp.Width, logoBmp.Width); + int combinedHeight = barcodeBmp.Height + logoBmp.Height; - // Center the barcode vertically and draw it on the left side - int barcodeY = (combinedHeight - barcodeBitmap.Height) / 2; - g.DrawImage( - barcodeBitmap, - new Rectangle(0, barcodeY, barcodeBitmap.Width, barcodeBitmap.Height)); + using (var combinedBmp = new Bitmap(combinedWidth, combinedHeight)) + { + using (var gCombined = Graphics.FromImage(combinedBmp)) + { + // White background for the combined image + gCombined.Clear(Color.White); - // Center the logo vertically and draw it on the right side - int logoY = (combinedHeight - logoBitmap.Height) / 2; - g.DrawImage( - logoBitmap, - new Rectangle(barcodeBitmap.Width, logoY, logoBitmap.Width, logoBitmap.Height)); - } + // Draw logo at the top + gCombined.DrawImage(logoBmp, 0, 0, logoBmp.Width, logoBmp.Height); - // Save the combined image to file - combinedBitmap.Save(combinedPath, ImageFormat.Png); + // Draw barcode below the logo + gCombined.DrawImage(barcodeBmp, 0, logoBmp.Height, barcodeBmp.Width, barcodeBmp.Height); } - } - // Save the pure barcode image for reference - barcodeBitmap.Save(barcodePath, ImageFormat.Png); + // Save the final combined image + combinedBmp.Save(combinedPath, ImageFormat.Png); + } } } } - // Output the full paths of the saved files + // Inform the user where the files are saved Console.WriteLine($"Barcode saved to: {Path.GetFullPath(barcodePath)}"); + Console.WriteLine($"Logo saved to: {Path.GetFullPath(logoPath)}"); Console.WriteLine($"Combined image saved to: {Path.GetFullPath(combinedPath)}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs b/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs index 87f499e..e87a6a6 100644 --- a/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs +++ b/gs1-barcode-types/generate-upc-barcode-with-databar-expanded-coupon-and-adjust-supplement-spacing-to-50-pixels.cs @@ -1,35 +1,36 @@ +// Title: Generate UPC‑A Barcode with DataBar Expanded Coupon and Custom Supplement Spacing +// Description: This example creates a UPC‑A barcode that includes a DataBar Expanded coupon and sets the supplement spacing to 50 pixels. +// Category-Description: Demonstrates Aspose.BarCode generation of composite barcodes using EncodeTypes.UpcaGs1DatabarCoupon. It showcases configuring the Coupon.SupplementSpace property, a common requirement when integrating UPC‑A with DataBar Expanded for retail coupons. Developers working with composite symbologies, supplement adjustments, and image output will find this pattern useful. +// Prompt: Generate a UPC‑A barcode with a DataBar Expanded coupon and adjust supplement spacing to 50 pixels. +// Tags: upc-a, databar expanded, supplement spacing, barcode generation, aspose.barcode + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generation of a UPC‑A DataBar Expanded coupon barcode using Aspose.BarCode. +/// Example program that generates a UPC‑A barcode containing a DataBar Expanded coupon +/// and customizes the supplement spacing. /// class Program { /// - /// Entry point of the application. Generates a barcode image and saves it to disk. + /// Entry point of the example. Creates the barcode, configures supplement spacing, + /// and saves the result as a PNG image. /// static void Main() { - // Define the barcode content. - // Format: (... ) - string codeText = "514141100906(8110)106141416543213500110000310123196000"; - - // Specify the output file path for the generated PNG image. - string outputPath = "upc_databar_expanded.png"; - - // Initialize the barcode generator for UPC‑A DataBar Expanded coupon symbology. - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, codeText)) + // Initialize the barcode generator for UPC‑A with a DataBar Expanded coupon + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon)) { - // Set the spacing (in points) between the main barcode and its supplement. + // Define the composite code text (UPC‑A part followed by DataBar part) + generator.CodeText = "514141100906(8110)106141416543213500110000310123196000"; + + // Adjust the supplement (coupon) spacing to 50 pixels generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 50f; - // Render and save the barcode image as a PNG file. - generator.Save(outputPath); + // Save the generated barcode image to a file + generator.Save("upc_a_databar_coupon.png"); } - - // Inform the user where the barcode image has been saved. - Console.WriteLine($"Barcode saved to: {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs b/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs index 2adc72d..77e0482 100644 --- a/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs +++ b/gs1-barcode-types/produce-gs1-code-128-barcode-apply-anti-aliasing-and-save-image-with-24-bit-color-depth.cs @@ -1,37 +1,41 @@ +// Title: Generate GS1 Code 128 barcode with anti-aliasing and 24-bit PNG output +// Description: Demonstrates creating a GS1 Code 128 barcode, applying anti-aliasing for smooth rendering, and saving it as a 24‑bit PNG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating how to use the BarcodeGenerator class with EncodeTypes.GS1Code128. It shows typical tasks such as setting symbology, configuring rendering options like anti‑aliasing, and specifying colors before saving to a common image format. Developers looking for barcode creation, image quality tuning, and format-specific output will find similar examples useful. +// Prompt: Produce a GS1 Code 128 barcode, apply anti‑aliasing, and save the image with 24‑bit color depth. +// Tags: gs1, code128, barcode, generation, anti-aliasing, png, 24-bit, aspose.barcode + using System; -using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.BarCode; +using Aspose.Drawing; -namespace BarcodeExample +/// +/// Example program that generates a GS1 Code 128 barcode, +/// applies anti‑aliasing for smoother rendering, and saves it as a 24‑bit PNG image. +/// +class Program { /// - /// Demonstrates generating a GS1 Code128 barcode using Aspose.BarCode. + /// Entry point of the example. Creates the barcode, configures rendering options, + /// and writes the output file. /// - class Program + static void Main() { - /// - /// Entry point of the application. Generates a barcode image and saves it to disk. - /// - static void Main() - { - // Define the GS1 Code128 data (Application Identifier 01 - GTIN) - string codeText = "(01)12345678901231"; - - // Specify the output file name and location - string outputPath = "gs1code128.png"; + // GS1 Code 128 requires AI parentheses, e.g., (01) for GTIN + const string gs1Code128Text = "(01)12345678901231"; - // Initialize the barcode generator with GS1 Code128 symbology and the data - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) - { - // Turn on anti‑aliasing to improve visual quality of the rendered image - generator.Parameters.UseAntiAlias = true; + // Create a generator for the GS1 Code 128 symbology + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code128Text)) + { + // Enable anti‑aliasing for smoother rendering + generator.Parameters.UseAntiAlias = true; - // Save the generated barcode as a PNG file (default 24‑bit color depth) - generator.Save(outputPath); - } + // Set foreground (bars) and background colors – default PNG is 24‑bit + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Inform the user where the barcode image was saved - Console.WriteLine($"Barcode saved to {outputPath}"); + // Save the barcode as a PNG file (24‑bit color depth) + generator.Save("gs1code128.png"); } } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs b/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs index d560469..c5dd7ef 100644 --- a/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs +++ b/gs1-barcode-types/produce-gs1-code-128-barcode-write-image-bytes-to-memorystream-and-return-as-api-response.cs @@ -1,48 +1,54 @@ +// Title: Generate GS1 Code 128 barcode and return as API response +// Description: Demonstrates creating a GS1 Code 128 barcode, writing the PNG image to a MemoryStream, and returning the image bytes (as Base64) suitable for an API response. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating how to use BarcodeGenerator with EncodeTypes.GS1Code128, configure barcode parameters, and output the image in PNG format. Developers often need to generate GS1-compliant barcodes for product identification and return them via web APIs; this snippet shows the typical workflow using Aspose.BarCode classes such as BarcodeGenerator, BarCodeImageFormat, and related parameter settings. +// Prompt: Produce a GS1 Code 128 barcode, write image bytes to a MemoryStream, and return as an API response. +// Tags: gs1, code128, barcode, generation, png, memorystream, api, response + using System; using System.IO; using System.Text; using Aspose.BarCode; using Aspose.BarCode.Generation; -using Aspose.BarCode.BarCodeRecognition; using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a GS1 Code 128 barcode and outputting its Base64 representation. +/// Example program that generates a GS1 Code 128 barcode, +/// writes the PNG image to a , +/// and outputs the image bytes as a Base64 string (simulating an API response). /// class Program { /// - /// Entry point of the application. Generates a barcode, encodes it as PNG, and writes the Base64 string to console. + /// Entry point of the example. Generates the barcode and writes the result to the console. /// static void Main() { - // Define the GS1 Code 128 text, including Application Identifier (01) for GTIN. - string codeText = "(01)12345678901231"; - - // Specify the encoding type for GS1 Code 128. - BaseEncodeType encodeType = EncodeTypes.GS1Code128; + // Sample GS1 Code 128 data (AI (01) for GTIN) + const string gs1Code128Text = "(01)12345678901231"; - // Initialize the barcode generator with the chosen type and text. - using (var generator = new BarcodeGenerator(encodeType, codeText)) + // Create a memory stream to hold the generated barcode image + using (var imageStream = new MemoryStream()) { - // Ensure the checksum is always displayed (required for GS1 Code 128). - generator.Parameters.Barcode.ChecksumAlwaysShow = true; - - // Create a memory stream to hold the generated PNG image. - using (var ms = new MemoryStream()) + // Initialize the barcode generator for GS1 Code 128 with the sample data + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1Code128Text)) { - // Save the barcode image into the memory stream in PNG format. - generator.Save(ms, BarCodeImageFormat.Png); + // Ensure the checksum is always shown (default for GS1 Code 128) + generator.Parameters.Barcode.ChecksumAlwaysShow = true; - // Retrieve the image bytes from the memory stream. - byte[] barcodeBytes = ms.ToArray(); + // Save the barcode image as PNG into the memory stream + generator.Save(imageStream, BarCodeImageFormat.Png); + } - // Convert the image bytes to a Base64 string to simulate an API response. - string base64 = Convert.ToBase64String(barcodeBytes); + // Reset the stream position to the beginning for reading + imageStream.Position = 0; - // Output the Base64 string to the console. - Console.WriteLine(base64); - } + // In a real API you would return the stream directly. + // Here we demonstrate by converting the image bytes to a Base64 string. + byte[] imageBytes = imageStream.ToArray(); + string base64Image = Convert.ToBase64String(imageBytes); + + // Output the Base64 string (simulating an API response body) + Console.WriteLine(base64Image); } } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs b/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs index e771d2e..342bc42 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-databar-coupon-then-programmatically-merge-it-with-product-label-image.cs @@ -1,3 +1,9 @@ +// Title: Generate UPC‑A DataBar Coupon barcode and merge with product label +// Description: Demonstrates creating a UPC‑A barcode with a GS1 DataBar coupon payload and combining it with an existing product label image. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation and image manipulation category. It showcases the use of BarcodeGenerator with EncodeTypes.UpcaGs1DatabarCoupon, setting visual parameters, and merging the generated barcode bitmap onto a product label using Aspose.Drawing graphics. Developers often need to create combined label images for retail packaging, where a barcode is placed on top of product artwork. +// Prompt: Produce a UPC‑A barcode with a DataBar coupon, then programmatically merge it with a product label image. +// Tags: upc-a, databar, coupon, barcode-generation, image-merge, png, aspose.barcode, aspose.drawing + using System; using System.IO; using Aspose.BarCode; @@ -6,81 +12,81 @@ using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a UPC‑A GS1 DataBar coupon barcode, -/// compositing it onto a simple product label, and saving the result as a PNG file. +/// Example program that generates a UPC‑A DataBar coupon barcode, +/// saves it as an image, and merges it onto a product label picture. /// class Program { /// - /// Entry point of the application. - /// Generates a barcode, draws a product label, merges them, and writes the output image to a temporary folder. + /// Entry point of the example. Creates the barcode, merges it with a label, + /// and writes the resulting images to disk. /// static void Main() { - // Sample UPC‑A with DataBar coupon code text - string couponCode = "514141100906(8110)106141416543213500110000310123196000"; + // -------------------------------------------------------------------- + // Define file paths (adjust as needed for your environment) + // -------------------------------------------------------------------- + const string productLabelPath = "product_label.png"; + const string barcodePath = "barcode.png"; + const string mergedPath = "merged_label.png"; - // Generate barcode image into a memory stream - using (var barcodeStream = new MemoryStream()) + // Verify that the product label image exists before proceeding + if (!File.Exists(productLabelPath)) { - // Create a barcode generator for the specified encode type and data - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, couponCode)) - { - // Save the generated barcode as PNG into the memory stream - generator.Save(barcodeStream, BarCodeImageFormat.Png); - } + Console.WriteLine($"Error: Product label image not found at '{productLabelPath}'."); + return; + } - // Reset stream position to the beginning for subsequent reading - barcodeStream.Position = 0; + // -------------------------------------------------------------------- + // Prepare the barcode data: UPC‑A with GS1 DataBar coupon payload + // -------------------------------------------------------------------- + const string couponCodeText = "514141100906(8110)106141416543213500110000310123196000"; - // Load the generated barcode image from the stream into a bitmap - using (var barcodeBitmap = new Bitmap(barcodeStream)) - { - // Define dimensions for the placeholder product label - int labelWidth = 600; - int labelHeight = 400; + // Create a BarcodeGenerator for the UPC‑A DataBar coupon symbology + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1DatabarCoupon, couponCodeText)) + { + // Optional visual customizations + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black; + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Create a blank label bitmap with a 32‑bit ARGB pixel format - using (var labelBitmap = new Bitmap(labelWidth, labelHeight, PixelFormat.Format32bppArgb)) - { - // Obtain a graphics object for drawing on the label bitmap - using (var graphics = Graphics.FromImage(labelBitmap)) - { - // Fill the label background with white color - graphics.Clear(Color.White); + // Enable automatic sizing using interpolation + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - // Draw the product name near the top-left corner - graphics.DrawString( - "Sample Product", - new Font("Arial", 24f), - new SolidBrush(Color.Black), - new PointF(20f, 20f)); + // Set desired image dimensions (points) + generator.Parameters.ImageWidth.Point = 300f; + generator.Parameters.ImageHeight.Point = 150f; - // Draw a short product description below the name - graphics.DrawString( - "Description: High‑quality item", - new Font("Arial", 14f), - new SolidBrush(Color.DarkGray), - new PointF(20f, 60f)); + // ---------------------------------------------------------------- + // Generate the barcode bitmap + // ---------------------------------------------------------------- + using (Bitmap barcodeBitmap = generator.GenerateBarCodeImage()) + { + // Save the standalone barcode image (optional) + barcodeBitmap.Save(barcodePath, ImageFormat.Png); - // Calculate position to center the barcode at the bottom of the label - int barcodeX = (labelWidth - barcodeBitmap.Width) / 2; - int barcodeY = labelHeight - barcodeBitmap.Height - 20; // 20 px margin from bottom + // Load the existing product label image + using (Image productImage = Image.FromFile(productLabelPath)) + { + // Prepare a graphics object for drawing onto the label + using (Graphics graphics = Graphics.FromImage(productImage)) + { + // Define placement margin and calculate position (bottom‑left) + int margin = 50; + int posX = margin; + int posY = productImage.Height - barcodeBitmap.Height - margin; - // Render the barcode onto the label bitmap - graphics.DrawImage(barcodeBitmap, barcodeX, barcodeY, barcodeBitmap.Width, barcodeBitmap.Height); + // Draw the barcode onto the label at the calculated coordinates + graphics.DrawImage(barcodeBitmap, posX, posY, barcodeBitmap.Width, barcodeBitmap.Height); } - // Determine output file path in the system's temporary directory - string outputPath = Path.Combine(Path.GetTempPath(), "ProductLabelWithBarcode.png"); - - // Save the combined label and barcode image as PNG - labelBitmap.Save(outputPath, ImageFormat.Png); - - // Inform the user where the file was saved - Console.WriteLine($"Merged image saved to: {outputPath}"); + // Save the combined label image + productImage.Save(mergedPath, ImageFormat.Png); } } } + + // Inform the user where the output files are located + Console.WriteLine($"Barcode image saved to: {barcodePath}"); + Console.WriteLine($"Merged label image saved to: {mergedPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs b/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs index 493f9c3..0173a76 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-embedded-gs1-code128-coupon-and-define-30-pixel-supplement-space.cs @@ -1,33 +1,42 @@ +// Title: Generate UPC‑A barcode with embedded GS1 Code128 coupon and 30‑pixel supplement +// Description: Demonstrates creating a UPC‑A barcode that includes a GS1 Code128 coupon and sets a 30‑pixel supplement space. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on composite symbologies that combine UPC‑A with GS1‑Code128 coupons. It showcases the use of BarcodeGenerator, EncodeTypes, and coupon parameters to embed supplemental data, a common requirement for retail and promotional barcode creation. Developers often need to generate such combined barcodes for product labeling and coupon integration. +// Prompt: Produce a UPC‑A barcode with an embedded GS1 Code128 coupon and define 30‑pixel supplement space. +// Tags: upc-a, gs1-code128, coupon, supplement, barcode generation, aspnet, png + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generation of a UPC‑A barcode with a GS1‑Code128 coupon using Aspose.BarCode. +/// Example program that creates a UPC‑A barcode with an embedded GS1‑Code128 coupon +/// and configures a 30‑pixel supplement space. /// class Program { /// - /// Entry point of the application that generates a UPC‑A barcode with an embedded GS1‑Code128 coupon. + /// Entry point. Generates the barcode and saves it as a PNG file. /// static void Main() { - // Example UPC‑A barcode with an embedded GS1‑Code128 coupon. - // Codetext format: "UPCA part (GS1Code128 part)" + // Define the barcode text. + // Format: "UPCA part (GS1Code128 part)" const string codeText = "514141100906(8102)03"; - // Create the generator for the UpcaGs1Code128Coupon symbology. + // Define the output file name. + const string outputPath = "upc_gs1code128_coupon.png"; + + // Initialize the generator for the composite UPC‑A with GS1‑Code128 coupon symbology. using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) { - // Define a 30‑pixel supplement (coupon) space. - generator.Parameters.Barcode.Coupon.SupplementSpace.Point = 30f; + // Set the supplement (coupon) space to 30 pixels. + generator.Parameters.Barcode.Coupon.SupplementSpace.Pixels = 30f; - // Save the barcode image to a file. - const string outputPath = "upc_a_gs1_coupon.png"; - generator.Save(outputPath); - - // Inform the user where the barcode was saved. - Console.WriteLine($"Barcode saved to: {outputPath}"); + // Save the generated barcode image as PNG. + generator.Save(outputPath, BarCodeImageFormat.Png); } + + // Inform the user where the barcode image was saved. + Console.WriteLine($"Barcode saved to {outputPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs b/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs index 14fe728..f43faf3 100644 --- a/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs +++ b/gs1-barcode-types/produce-upc-barcode-with-gs1-code128-coupon-then-embed-image-into-html-page.cs @@ -1,52 +1,52 @@ +// Title: Generate UPC‑A barcode with GS1 Code128 coupon and embed in HTML +// Description: Demonstrates creating a UPC‑A barcode that includes a GS1 Code128 coupon, converting it to PNG, and embedding the image directly into an HTML page using a data URI. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, showcasing the use of BarcodeGenerator with EncodeTypes.UpcaGs1Code128Coupon. It illustrates typical scenarios such as creating combined symbologies for retail packaging, generating barcode images, and embedding them in web content. Developers often need to produce barcode graphics for e‑commerce, inventory, or promotional coupons, and this snippet provides a concise reference. +// Prompt: Produce a UPC‑A barcode with a GS1 Code128 coupon, then embed the image into an HTML page. +// Tags: upc-a, gs1-code128, coupon, barcode generation, image embedding, html, aspose.barcode, png + using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; +using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a UPC‑A with GS1‑Code128 coupon barcode, -/// saving it as an image, and embedding it in a simple HTML page. +/// Demonstrates generating a UPC‑A barcode with a GS1 Code128 coupon and embedding it into an HTML file. /// class Program { /// - /// Entry point of the application. - /// Generates the barcode, converts it to Base64, creates an HTML file, - /// and writes both the image and HTML to disk. + /// Entry point. Generates the barcode, converts it to a Base64 PNG, and writes an HTML file containing the image. /// - /// Command‑line arguments (not used). - static void Main(string[] args) + static void Main() { - // Define output file names for the image and HTML page. - string imagePath = "barcode.png"; - string htmlPath = "barcode.html"; - - // UPC‑A part + GS1‑Code128 coupon part to encode. - string codeText = "514141100906(8102)03"; - - // Generate the barcode image using Aspose.BarCode. - using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, codeText)) + // Initialize the barcode generator for UPC‑A with a GS1 Code128 coupon. + // Example codetext: "514141100906(8102)03" + using (var generator = new BarcodeGenerator(EncodeTypes.UpcaGs1Code128Coupon, "514141100906(8102)03")) { - // Save the generated barcode as a PNG file (default format). - generator.Save(imagePath); - } - - // Read the saved PNG file into a byte array. - byte[] imageBytes = File.ReadAllBytes(imagePath); - // Convert the image bytes to a Base64 string for embedding in HTML. - string base64Image = Convert.ToBase64String(imageBytes); + // Generate the barcode image as a bitmap. + using (Bitmap bitmap = generator.GenerateBarCodeImage()) + { + // Save the bitmap to a memory stream in PNG format. + using (var memoryStream = new MemoryStream()) + { + bitmap.Save(memoryStream, ImageFormat.Png); + byte[] imageBytes = memoryStream.ToArray(); - // Construct a minimal HTML document that displays the barcode image. - string htmlContent = $"UPC‑A with GS1‑Code128 Coupon" + - $"

Barcode

" + - $"\"Barcode\"/" + - $""; + // Convert the PNG bytes to a Base64 string for embedding. + string base64Image = Convert.ToBase64String(imageBytes); - // Write the HTML content to the specified file. - File.WriteAllText(htmlPath, htmlContent); + // Build a simple HTML page that embeds the barcode image using a data URI. + string htmlContent = $"UPC‑A GS1‑Code128 Coupon" + + $"

UPC‑A with GS1‑Code128 Coupon

" + + $"\"Barcode\"/" + + $""; - // Output the locations of the generated files to the console. - Console.WriteLine($"Barcode image saved to: {imagePath}"); - Console.WriteLine($"HTML page saved to: {htmlPath}"); + // Write the HTML content to a file named 'barcode.html'. + File.WriteAllText("barcode.html", htmlContent); + } + } + } } } \ No newline at end of file diff --git a/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs b/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs index 2a4e9d8..38a8743 100644 --- a/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs +++ b/gs1-barcode-types/render-gs1-code-128-barcode-retrieve-image-bytes-and-store-them-in-database-column.cs @@ -1,60 +1,64 @@ +// Title: Render GS1 Code 128 barcode and store image bytes +// Description: Demonstrates generating a GS1 Code 128 barcode, extracting the PNG image bytes, and showing how to persist them to a database column. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and image handling classes such as Bitmap and ImageFormat. Typical scenarios include creating product barcodes, exporting them as image streams, and saving the binary data to a database for later retrieval. Developers often need to render barcodes, obtain raw bytes, and integrate them with data storage solutions. +// Prompt: Render a GS1 Code 128 barcode, retrieve image bytes, and store them in a database column. +// Tags: gs1 code128, barcode generation, image output, png, database storage, aspose.barcode, aspose.drawing + using System; using System.IO; using Aspose.BarCode; using Aspose.BarCode.Generation; +using Aspose.Drawing; +using Aspose.Drawing.Imaging; /// -/// Demonstrates generating a GS1‑128 barcode using Aspose.BarCode, -/// saving the image bytes to a file, and optionally writing the PNG image. +/// Example program that generates a GS1 Code 128 barcode, +/// converts it to PNG bytes, and demonstrates how those bytes could be stored in a database. /// class Program { /// - /// Entry point of the application. - /// Generates a GS1‑128 barcode, captures its PNG bytes, - /// and writes the bytes to disk for demonstration purposes. + /// Entry point of the example. Generates the barcode, extracts image bytes, + /// and writes the PNG file to disk (simulating database storage). /// static void Main() { - // Define the barcode content. - // GS1 Code 128 requires AI parentheses, e.g., (01) for GTIN. - string codeText = "(01)12345678901231"; - - // Variable to hold the generated barcode image bytes. - byte[] barcodeBytes; + // Sample GS1 Code 128 data (AI (01) with a 14‑digit GTIN) + const string gs1CodeText = "(01)12345678901231"; - // Use a memory stream to capture the PNG image generated by Aspose.BarCode. - using (var memoryStream = new MemoryStream()) + // Initialize the barcode generator for GS1 Code 128 + using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, gs1CodeText)) { - // Create a barcode generator for GS1‑128 with the specified text. - using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, codeText)) + // Optional: always show checksum in the human‑readable text + generator.Parameters.Barcode.ChecksumAlwaysShow = true; + + // Generate the barcode image as a Bitmap object + using (Bitmap bitmap = generator.GenerateBarCodeImage()) { - // Optional: display the checksum digit in the human‑readable text. - generator.Parameters.Barcode.ChecksumAlwaysShow = true; + // Save the bitmap to a memory stream to obtain raw PNG bytes + using (var ms = new MemoryStream()) + { + bitmap.Save(ms, ImageFormat.Png); + byte[] imageBytes = ms.ToArray(); - // Save the barcode image to the memory stream in PNG format. - generator.Save(memoryStream, BarCodeImageFormat.Png); - } + // ---- Substitute for database storage ---- + // In a real scenario you would store 'imageBytes' into a BLOB column, e.g.: + // using (var connection = new SqlConnection(connectionString)) + // { + // connection.Open(); + // using (var command = new SqlCommand("INSERT INTO Barcodes (Image) VALUES (@img)", connection)) + // { + // command.Parameters.Add("@img", SqlDbType.VarBinary, imageBytes.Length).Value = imageBytes; + // command.ExecuteNonQuery(); + // } + // } + // ----------------------------------------- - // Convert the memory stream contents to a byte array. - barcodeBytes = memoryStream.ToArray(); + // For the snippet runner, write the image to a local file instead + File.WriteAllBytes("gs1code128.png", imageBytes); + Console.WriteLine("Barcode image saved to 'gs1code128.png'."); + } + } } - - // ---------------------------------------------------------------------- - // In a real application you would store 'barcodeBytes' in a database column. - // For this example (no database available) we write the bytes to a file. - // ---------------------------------------------------------------------- - string binaryPath = "barcode_image.bin"; - - // Write the raw PNG bytes to a binary file. - File.WriteAllBytes(binaryPath, barcodeBytes); - Console.WriteLine($"Barcode image bytes written to {binaryPath}"); - - // Additionally, save the same PNG bytes with a .png extension for visual verification. - string pngPath = "gs1code128.png"; - - // Write the PNG image to disk. - File.WriteAllBytes(pngPath, barcodeBytes); - Console.WriteLine($"Barcode PNG saved to {pngPath}"); } } \ No newline at end of file diff --git a/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs b/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs index 2654b7c..390e7e9 100644 --- a/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs +++ b/gs1-barcode-types/set-barcode-size-to-200-100-pixels-for-gs1-code-128-barcode-and-export-as-jpeg.cs @@ -1,32 +1,37 @@ +// Title: Set GS1 Code 128 barcode size and export as JPEG +// Description: Demonstrates how to configure a GS1 Code 128 barcode's dimensions to 200 × 100 pixels and save it as a JPEG image. +// Category-Description: This example belongs to the Aspose.BarCode generation category, illustrating image size manipulation using the BarcodeGenerator class. Developers often need to control barcode dimensions for UI layout, printing, or integration into documents; the API provides AutoSizeMode and image size properties to achieve precise pixel sizing. +// Prompt: Set barcode size to 200 × 100 pixels for a GS1 Code 128 barcode and export as JPEG. +// Tags: gs1code128, barcode size, jpeg export, aspnet, aspose.barcode, generation + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; /// -/// Demonstrates generating a GS1 Code 128 barcode using Aspose.BarCode. +/// Demonstrates setting a GS1 Code 128 barcode's size to 200 × 100 pixels and saving it as a JPEG file. /// class Program { /// - /// Entry point of the application. Generates a barcode and saves it as a JPEG file. + /// Entry point of the example. Generates the barcode, configures size, and saves the image. /// static void Main() { - // Initialize a barcode generator for GS1 Code 128 with sample GS1 data + // Create a GS1 Code 128 barcode generator with sample GS1 data using (var generator = new BarcodeGenerator(EncodeTypes.GS1Code128, "(01)12345678901231")) { - // Configure automatic sizing to choose the nearest size that fits the target dimensions - generator.Parameters.AutoSizeMode = AutoSizeMode.Nearest; + // Enable automatic sizing mode that respects explicit image dimensions + generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation; - // Set desired image width and height in points (1 point = 1/72 inch) + // Set the desired image width to 200 pixels generator.Parameters.ImageWidth.Point = 200f; + + // Set the desired image height to 100 pixels generator.Parameters.ImageHeight.Point = 100f; - // Save the generated barcode image to a JPEG file + // Save the generated barcode as a JPEG image file generator.Save("gs1code128.jpg"); } - - // Inform the user that the barcode has been generated and saved - Console.WriteLine("Barcode generated and saved as gs1code128.jpg"); } } \ No newline at end of file diff --git a/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs b/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs index 40456d9..2d51997 100644 --- a/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs +++ b/gs1-barcode-types/set-foreground-color-to-blue-and-background-color-to-white-for-gs1-datamatrix-barcode.cs @@ -1,37 +1,43 @@ +// Title: Set colors for GS1 DataMatrix barcode +// Description: Demonstrates how to set the foreground color to blue and background color to white when generating a GS1 DataMatrix barcode using Aspose.BarCode. +// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on visual customization of barcodes. It showcases the use of BarcodeGenerator, EncodeTypes, and color properties to control appearance, a common requirement for branding and readability in applications that generate DataMatrix symbols. +// Prompt: Set foreground color to blue and background color to white for a GS1 DataMatrix barcode. +// Tags: datamatrix, gs1, color, foreground, background, png, aspose.barcode, generation + using System; using Aspose.BarCode; using Aspose.BarCode.Generation; using Aspose.Drawing; /// -/// Demonstrates generating a GS1 DataMatrix barcode using Aspose.BarCode. +/// Generates a GS1 DataMatrix barcode with custom foreground and background colors. /// class Program { /// - /// Entry point of the application. Generates a GS1 DataMatrix barcode and saves it as a PNG file. + /// Entry point of the example. Creates a GS1 DataMatrix barcode, sets its colors, and saves it as a PNG file. /// static void Main() { - // Define the barcode text using GS1 Application Identifier (AI) 01 for GTIN. + // Define the GS1 DataMatrix code text (GTIN example) string codeText = "(01)12345678901231"; - // Initialize the barcode generator with GS1 DataMatrix symbology and the specified text. + // Initialize the barcode generator for GS1 DataMatrix with the specified text using (var generator = new BarcodeGenerator(EncodeTypes.GS1DataMatrix, codeText)) { - // Configure the barcode appearance: set the bar (foreground) color to blue. - generator.Parameters.Barcode.BarColor = Color.Blue; + // Set the foreground (bars) color to blue + generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Blue; - // Set the background color of the image to white. - generator.Parameters.BackColor = Color.White; + // Set the background color to white + generator.Parameters.BackColor = Aspose.Drawing.Color.White; - // Define the output file path for the generated PNG image. + // Define the output file path and format (PNG) string outputPath = "gs1datamatrix.png"; - // Save the generated barcode image to the specified path. - generator.Save(outputPath); + // Save the generated barcode image to the file system + generator.Save(outputPath, BarCodeImageFormat.Png); - // Inform the user that the barcode has been saved. + // Inform the user where the barcode image was saved Console.WriteLine($"Barcode saved to {outputPath}"); } }