Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,68 +1,49 @@
// Title: Generate a compact Mailmark barcode for small labels
// Description: Demonstrates how to adjust the module size and padding of a Mailmark barcode to create a compact image suitable for small label printing.
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode symbologies such as Mailmark. It showcases the use of ComplexBarcodeGenerator, MailmarkCodetext, and barcode parameter settings like XDimension, AutoSizeMode, and padding. Developers often need to create high‑density barcodes for limited space applications, and this snippet provides a concise reference for those scenarios.
// Title: Generate a compact Mailmark barcode with reduced module size
// Description: Demonstrates how to create a Mailmark barcode, adjust its X‑dimension for a smaller module size, and remove padding to fit small labels.
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as Mailmark. It showcases the use of ComplexBarcodeGenerator, MailmarkCodetext, and barcode parameter settings (XDimension, Padding) to customize output. Developers often need to produce compact barcodes for limitedspace applications like product labels, shipping tags, or inventory stickers.
// Prompt: Adjust barcode module size to produce a compact Mailmark barcode suitable for small labels.
// Tags: mailmark, barcode, module size, compact, small labels, generation, aspose.barcode
// Tags: mailmark, barcode, generation, png, complexbarcodegenerator, mailmarkcodetext, xdimension, padding

using System;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.BarCode.ComplexBarcode;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.Drawing;

/// <summary>
/// Program demonstrating compact Mailmark barcode generation.
/// Demonstrates generating a Mailmark barcode with a reduced module size for compact label printing.
/// </summary>
class Program
{
/// <summary>
/// Entry point. Generates a Mailmark barcode with reduced module size and padding, then saves it as PNG.
/// Entry point. Creates Mailmark codetext, configures barcode parameters, and saves the image.
/// </summary>
static void Main()
{
// Prepare Mailmark codetext with required fields
// Initialize Mailmark codetext with required values.
var mailmark = new MailmarkCodetext();
mailmark.Format = 4; // unspecified/default format for compact barcode
mailmark.VersionID = 1;
mailmark.Class = "0";
mailmark.SupplychainID = 384224;
mailmark.ItemID = 16563762;
mailmark.DestinationPostCodePlusDPS = "EF61AH8T ";

// Create ComplexBarcodeGenerator for Mailmark
mailmark.Format = 4; // 4‑state Mailmark
mailmark.VersionID = 1; // version
mailmark.Class = "0"; // class as string
mailmark.SupplychainID = 384224; // supply chain identifier
mailmark.ItemID = 16563762; // item identifier
mailmark.DestinationPostCodePlusDPS = "EF61AH8T "; // trailing space required

// Create a generator for the complex Mailmark barcode.
using (var generator = new ComplexBarcodeGenerator(mailmark))
{
// Use interpolation auto-size mode so that XDimension controls overall size
generator.Parameters.AutoSizeMode = AutoSizeMode.Interpolation;

// Set a small module (dot) size for compactness
generator.Parameters.Barcode.XDimension.Point = 0.5f; // 0.5 point per module

// Reduce padding to keep the barcode tight on small labels
generator.Parameters.Barcode.Padding.Left.Point = 1f;
generator.Parameters.Barcode.Padding.Top.Point = 1f;
generator.Parameters.Barcode.Padding.Right.Point = 1f;
generator.Parameters.Barcode.Padding.Bottom.Point = 1f;
// Reduce module size for a compact barcode suitable for small labels.
generator.Parameters.Barcode.XDimension.Point = 0.5f; // small module width

// Optional: set foreground and background colors
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.BackColor = Color.White;
// Minimize padding to keep the barcode tight.
generator.Parameters.Barcode.Padding.Left.Point = 0f;
generator.Parameters.Barcode.Padding.Top.Point = 0f;
generator.Parameters.Barcode.Padding.Right.Point = 0f;
generator.Parameters.Barcode.Padding.Bottom.Point = 0f;

// Define output path
string outputPath = "mailmark_compact.png";

// Ensure the directory exists
string directory = Path.GetDirectoryName(Path.GetFullPath(outputPath));
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

// Save the barcode image
generator.Save(outputPath, BarCodeImageFormat.Png);
Console.WriteLine($"Compact Mailmark barcode saved to: {outputPath}");
// Save the generated barcode as a PNG image.
generator.Save("mailmark.png");
}

Console.WriteLine("Mailmark barcode generated: mailmark.png");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Title: Batch Mailmark Barcode Generation to BMP Files
// Description: Demonstrates generating Mailmark barcodes for a list of customer records and saving each barcode as an individual BMP image.
// Category-Description: This example belongs to the Aspose.BarCode generation category, focusing on complex barcode types such as Mailmark. It showcases the use of Aspose.BarCode.Generation.ComplexBarcodeGenerator and Aspose.BarCode.ComplexBarcode.MailmarkCodetext to create barcodes programmatically. Developers often need to batch‑process records, embed specific data fields, and export barcodes to image formats for printing or archival purposes.
// Title: Batch generation of Mailmark barcodes to BMP files
// Description: Demonstrates how to create Mailmark barcodes for multiple customer records and save each barcode as an individual BMP image.
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, focusing on complex barcode types such as Mailmark. It showcases the use of ComplexBarcodeGenerator and MailmarkCodetext classes to produce high‑volume barcode images, a common requirement for logistics, mailing, and inventory systems. Developers often need to generate barcodes in bulk, customize codetext, and export them to various image formats.
// Prompt: Batch generate Mailmark barcodes from customer records, saving each as separate BMP files.
// Tags: mailmark, barcode, generation, bmp, aspose.barcode, complexbarcode
// Tags: mailmark, barcode generation, bmp, batch processing, aspose.barcode, complexbarcode, codetext

using System;
using System.Collections.Generic;
Expand All @@ -12,56 +12,70 @@
using Aspose.BarCode.ComplexBarcode;

/// <summary>
/// Generates Mailmark barcodes for a collection of customer records and saves each barcode as a BMP file.
/// Example program that generates Mailmark barcodes for a list of customer records
/// and saves each barcode as a separate BMP file.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application. Creates an output folder, iterates over sample records,
/// builds Mailmark codetext, generates the barcode, and writes it to disk.
/// Entry point of the application. Iterates over sample customer data,
/// builds Mailmark codetext, generates the barcode image, and writes it to disk.
/// </summary>
static void Main()
{
// Define the output directory and ensure it exists
string outputDir = Path.Combine(Directory.GetCurrentDirectory(), "MailmarkBarcodes");
if (!Directory.Exists(outputDir))
// Sample customer records – in a real scenario these would come from a database or file.
var customers = new List<CustomerRecord>
{
Directory.CreateDirectory(outputDir);
}
new CustomerRecord { Class = "0", SupplychainID = 384224, ItemID = 16563762 },
new CustomerRecord { Class = "1", SupplychainID = 384224, ItemID = 16563763 },
new CustomerRecord { Class = "2", SupplychainID = 384224, ItemID = 16563764 },
new CustomerRecord { Class = "3", SupplychainID = 384224, ItemID = 16563765 },
new CustomerRecord { Class = "4", SupplychainID = 384224, ItemID = 16563766 }
};

// Sample customer records (limited to 5 for safe execution)
var records = new List<(int ItemID, string DestinationPostCodePlusDPS)>
// Determine output folder for generated BMP files.
string outputFolder = Path.Combine(Directory.GetCurrentDirectory(), "MailmarkBarcodes");
if (!Directory.Exists(outputFolder))
{
(16563762, "EF61AH8T "),
(16563763, "EF61AH8T "),
(16563764, "EF61AH8T "),
(16563765, "EF61AH8T "),
(16563766, "EF61AH8T ")
};
// Create the folder if it does not already exist.
Directory.CreateDirectory(outputFolder);
}

int index = 1;
foreach (var record in records)
foreach (var record in customers)
{
// Build the Mailmark codetext with required fields for each record
// Construct Mailmark codetext according to the specification.
var mailmark = new MailmarkCodetext
{
Format = 4, // 4‑state (unspecified/default)
VersionID = 1,
Class = "0", // Test/Null class
SupplychainID = 384224,
Format = 4, // 4‑state Mailmark.
VersionID = 1, // Version identifier.
Class = record.Class, // Class as string.
SupplychainID = record.SupplychainID,
ItemID = record.ItemID,
DestinationPostCodePlusDPS = record.DestinationPostCodePlusDPS
DestinationPostCodePlusDPS = "EF61AH8T " // Trailing space is required.
};

// Generate the barcode and save it as a BMP image
// Generate the barcode image using ComplexBarcodeGenerator.
using (var generator = new ComplexBarcodeGenerator(mailmark))
{
string filePath = Path.Combine(outputDir, $"Mailmark_{index}.bmp");
// Build file name and path for the current barcode.
string filePath = Path.Combine(outputFolder, $"Mailmark_{index}.bmp");
// Save the barcode as a BMP image.
generator.Save(filePath, BarCodeImageFormat.Bmp);
Console.WriteLine($"Saved Mailmark barcode to: {filePath}");
Console.WriteLine($"Saved Mailmark barcode #{index} to: {filePath}");
}

index++;
}

Console.WriteLine("All Mailmark barcodes have been generated.");
}

// Simple data holder for demonstration purposes.
private class CustomerRecord
{
public string Class { get; set; }
public int SupplychainID { get; set; }
public int ItemID { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,85 +1,105 @@
// Title: Mailmark Barcode Generation Performance: PNG vs JPEG
// Description: Demonstrates measuring generation time and file size when creating Mailmark barcodes in PNG and JPEG formats.
// Category-Description: This example belongs to the Aspose.BarCode generation category, showcasing the use of ComplexBarcodeGenerator to produce Mailmark symbology. It illustrates typical tasks such as configuring Mailmark codetext, rendering barcodes to different image formats, and profiling performance—common needs for developers integrating barcode creation into high‑throughput or size‑sensitive applications. The snippet highlights key API classes like MailmarkCodetext, ComplexBarcodeGenerator, and BarCodeImageFormat, serving as a reference for performance‑oriented barcode generation scenarios.
/// Prompt: Compare performance of generating Mailmark barcodes as PNG versus JPEG by measuring file size and generation time.
/// Tags: mailmark, barcode, performance, png, jpeg, generation, aspose.barcode, complexbarcodegenerator
// Title: Mailmark Barcode Generation: PNG vs JPEG Performance Comparison
// Description: Demonstrates generating Mailmark barcodes as PNG and JPEG images, measuring file size and generation time for each format.
// Category-Description: Shows how to use Aspose.BarCode's ComplexBarcodeGenerator to create Mailmark barcodes, covering image format selection, stream handling, and performance measurement. This example belongs to the barcode generation and image export category, where developers often need to compare output formats for size and speed.
// Prompt: Compare performance of generating Mailmark barcodes as PNG versus JPEG by measuring file size and generation time.
// Tags: mailmark, barcode, performance, png, jpeg, imageformat, complexbarcodegenerator, aspose.barcode

using System;
using System.Diagnostics;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using System.Diagnostics;
using Aspose.BarCode.ComplexBarcode;
using Aspose.Drawing.Imaging;
using Aspose.BarCode.Generation;

/// <summary>
/// Generates Mailmark barcodes in PNG and JPEG formats and compares their generation time and file size.
/// Generates a series of Mailmark barcodes in PNG and JPEG formats,
/// then reports file size and generation time for each format.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the example. Prepares Mailmark data, renders the barcode in two image formats,
/// and outputs average generation time and file size for each format.
/// Entry point of the example. Creates output directory, generates barcodes,
/// saves them as PNG and JPEG, and prints performance metrics.
/// </summary>
static void Main()
{
// Prepare a valid Mailmark codetext with required fields.
var mailmark = new MailmarkCodetext
{
Format = 4, // 4‑state barcode
VersionID = 1,
Class = "0",
SupplychainID = 384224,
ItemID = 16563762,
DestinationPostCodePlusDPS = "EF61AH8T "
};

// Define the image formats to be tested: PNG and JPEG.
var formats = new[]
// Ensure the output directory exists
string outputDir = "MailmarkOutput";
if (!Directory.Exists(outputDir))
{
BarCodeImageFormat.Png,
BarCodeImageFormat.Jpeg
};
Directory.CreateDirectory(outputDir);
}

const int iterations = 5; // Number of repetitions for averaging results.
// Number of barcode samples to generate
int sampleCount = 5;

// Iterate over each format and measure performance.
foreach (var format in formats)
for (int i = 0; i < sampleCount; i++)
{
long totalBytes = 0; // Accumulator for total file size.
long totalTicks = 0; // Accumulator for total elapsed ticks.
// Prepare Mailmark codetext with unique ItemID for each sample
var mailmark = new MailmarkCodetext
{
Format = 4, // 4‑state Mailmark
VersionID = 1,
Class = "0",
SupplychainID = 384224,
ItemID = 16563762 + i, // vary ItemID to keep records unique
DestinationPostCodePlusDPS = "EF61AH8T " // trailing space is required
};

// Run the generation multiple times to obtain average metrics.
for (int i = 0; i < iterations; i++)
// ---------- PNG generation ----------
string pngPath = Path.Combine(outputDir, $"mailmark_{i}_png.png");
long pngSize;
double pngMs;

using (var generator = new ComplexBarcodeGenerator(mailmark))
using (var pngStream = new MemoryStream())
{
// Create a generator for the Mailmark barcode.
using (var generator = new ComplexBarcodeGenerator(mailmark))
{
// Use a memory stream to avoid disk I/O overhead.
using (var ms = new MemoryStream())
{
// Start timing the Save operation.
var sw = Stopwatch.StartNew();
generator.Save(ms, format);
sw.Stop();
// Measure time to render PNG
var sw = Stopwatch.StartNew();
generator.Save(pngStream, BarCodeImageFormat.Png);
sw.Stop();
pngMs = sw.Elapsed.TotalMilliseconds;

// Accumulate elapsed time and resulting byte size.
totalTicks += sw.ElapsedTicks;
totalBytes += ms.Length;
}
// Write PNG stream to file
pngStream.Position = 0;
using (var file = new FileStream(pngPath, FileMode.Create, FileAccess.Write))
{
pngStream.CopyTo(file);
}
}

// Compute average generation time in milliseconds.
double avgMs = (totalTicks * 1000.0) / Stopwatch.Frequency / iterations;
// Compute average file size in kilobytes.
double avgKb = (totalBytes / 1024.0) / iterations;
// Retrieve PNG file size
pngSize = new FileInfo(pngPath).Length;

// ---------- JPEG generation ----------
string jpegPath = Path.Combine(outputDir, $"mailmark_{i}_jpeg.jpg");
long jpegSize;
double jpegMs;

// Friendly format name for output.
string formatName = format == BarCodeImageFormat.Png ? "PNG" : "JPEG";
using (var generator = new ComplexBarcodeGenerator(mailmark))
using (var jpegStream = new MemoryStream())
{
// Measure time to render JPEG
var sw = Stopwatch.StartNew();
generator.Save(jpegStream, BarCodeImageFormat.Jpeg);
sw.Stop();
jpegMs = sw.Elapsed.TotalMilliseconds;

// Display the averaged results.
Console.WriteLine($"{formatName} - Average generation time: {avgMs:F2} ms, Average file size: {avgKb:F2} KB");
// Write JPEG stream to file
jpegStream.Position = 0;
using (var file = new FileStream(jpegPath, FileMode.Create, FileAccess.Write))
{
jpegStream.CopyTo(file);
}
}

// Retrieve JPEG file size
jpegSize = new FileInfo(jpegPath).Length;

// Output comparison results for the current record
Console.WriteLine($"Record {i}: PNG - {pngSize} bytes, {pngMs:F2} ms; JPEG - {jpegSize} bytes, {jpegMs:F2} ms");
}

// Indicate that the performance comparison has finished
Console.WriteLine("Performance comparison completed.");
}
}
Loading
Loading