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,7 +1,8 @@
// Title: Barcode Generation and Reading with Minimal XDimension Filtering
// Description: Demonstrates generating a Code128 barcode, saving it to an image, and reading it back while filtering sub‑pixel noise using QualitySettings.UseMinimalXDimension.
// Title: Minimal XDimension Filtering for Code128 Barcode Recognition
// Description: Demonstrates how to generate a Code128 barcode, save it as PNG, and recognize it while filtering sub‑pixel noise using QualitySettings.
// Category-Description: This example belongs to the Aspose.BarCode image generation and recognition category. It showcases the use of BarcodeGenerator for creating barcodes and BarCodeReader with QualitySettings to improve detection accuracy. Developers often need to fine‑tune XDimension settings to handle low‑resolution scans or noisy images, making this pattern common in barcode processing pipelines.
// Prompt: Activate QualitySettings.UseMinimalXDimension and set MinimalXDimension to 1 pixel to filter sub‑pixel noise.
// Tags: code128, barcode generation, barcode recognition, minimalxdimension, qualitysettings, aspnet
// Tags: code128, generation, recognition, png, barcodegenerator, barcodereader, qualitysettings, xdimension

using System;
using System.IO;
Expand All @@ -10,53 +11,45 @@
using Aspose.BarCode.BarCodeRecognition;

/// <summary>
/// Example program that creates a Code128 barcode image and reads it back
/// using minimal XDimension filtering to suppress sub‑pixel noise.
/// Generates a Code128 barcode, saves it as an image, and reads it back using minimal XDimension filtering
/// to suppress sub‑pixel noise during recognition.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application.
/// Generates a barcode, saves it, and then reads it with quality settings applied.
/// Entry point of the example. Executes barcode generation, saves the image, and performs recognition.
/// </summary>
static void Main()
{
// ------------------------------------------------------------
// 1. Generate a sample barcode image and save it to disk.
// ------------------------------------------------------------
string imagePath = "sample.png";
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample123"))
// Define the output file path for the generated barcode image.
string imagePath = "sample_barcode.png";

// Generate a simple Code128 barcode with the value "123456" and save it as a PNG file.
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123456"))
{
// Save the generated barcode as a PNG file.
// Additional image configuration (size, colors, etc.) can be set here if needed.
generator.Save(imagePath);
}

// ------------------------------------------------------------
// 2. Verify that the barcode image was successfully created.
// ------------------------------------------------------------
// Verify that the barcode image was successfully created.
if (!File.Exists(imagePath))
{
Console.WriteLine($"Error: Barcode image not found at '{imagePath}'.");
Console.WriteLine($"Failed to create barcode image at '{imagePath}'.");
return;
}

// ------------------------------------------------------------
// 3. Read the barcode with minimal XDimension filtering enabled.
// ------------------------------------------------------------
// Initialize a BarCodeReader for the saved image, specifying that we expect a Code128 barcode.
using (var reader = new BarCodeReader(imagePath, DecodeType.Code128))
{
// Activate UseMinimalXDimension mode to ignore sub‑pixel variations.
// Activate minimal XDimension filtering to ignore sub‑pixel noise.
reader.QualitySettings.XDimension = XDimensionMode.UseMinimalXDimension;
reader.QualitySettings.MinimalXDimension = 1f; // 1 pixel

// Set the minimal XDimension threshold to 1 pixel.
reader.QualitySettings.MinimalXDimension = 1f;

// --------------------------------------------------------
// 4. Process and output detected barcode information.
// --------------------------------------------------------
// Perform barcode recognition and output the results.
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"Detected CodeText: {result.CodeText}");
Console.WriteLine($"Detected Type: {result.CodeTypeName}");
Console.WriteLine($"Detected Text: {result.CodeText}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
// Title: Generate Code128 Barcode with Custom XDimension
// Description: Demonstrates setting the XDimension to 3 pixels for a Code128 barcode and saving it as a PNG image.
// Description: Demonstrates how to generate a Code128 barcode image and set the XDimension to 3 pixels for proper 1D element width.
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and QualitySettings to control barcode dimensions. Developers often need to customize module width (XDimension) to meet printing standards or scanner requirements. The snippet shows typical steps: creating a generator, disabling auto‑size, setting XDimension, and saving the image.
// Prompt: Adjust QualitySettings.XDimension to 3 pixels to match typical 1D barcode element widths.
// Tags: code128, xdimension, barcode, generation, png, aspose.barcode
// Tags: barcode, code128, generation, png, xdimension, aspose.barcode, qualitysettings

using System;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.Drawing;

/// <summary>
/// Example program that creates a Code128 barcode with a custom XDimension (module width)
/// and saves the result as a PNG file.
/// Example program that creates a Code128 barcode image with a custom XDimension.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application. Generates the barcode and writes a confirmation message.
/// Entry point of the application. Generates and saves a barcode PNG file.
/// </summary>
static void Main()
{
// Initialize a barcode generator for Code128 with the sample text "1234567890".
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
{
// Set XDimension to 3 pixels (module width) to match typical 1D barcode element widths.
generator.Parameters.Barcode.XDimension.Point = 3f;
// Define the output file path for the generated barcode image.
const string outputPath = "barcode.png";

// Disable automatic sizing so that the custom XDimension is respected.
// Initialize a BarcodeGenerator for Code128 symbology with sample data.
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "123456"))
{
// Disable automatic sizing so the manually set XDimension is respected.
generator.Parameters.AutoSizeMode = AutoSizeMode.None;

// Optionally set a bar height (in points) for better visual appearance.
generator.Parameters.Barcode.BarHeight.Point = 50f;
// Set the XDimension (module width) to 3 pixels, matching typical 1D barcode element widths.
generator.Parameters.Barcode.XDimension.Pixels = 3f;

// Save the generated barcode image to a PNG file.
generator.Save("code128_xdimension_3.png");
// Save the barcode as a PNG image to the specified path.
generator.Save(outputPath, BarCodeImageFormat.Png);
}

// Inform the user that the barcode has been generated.
Console.WriteLine("Barcode generated with XDimension set to 3 pixels.");
// Inform the user where the barcode image has been saved.
Console.WriteLine($"Barcode image saved to {outputPath}");
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,70 @@
// Title: Custom Color Scheme for Barcode Generation
// Description: Demonstrates how to apply a dark bar color and a light background to improve detection of dark barcodes on light backgrounds.
// Title: Custom Color Barcode Generation and Recognition
// Description: Demonstrates generating a Code128 barcode with a dark bar color on a light background and recognizing it using Aspose.BarCode.
// Category-Description: This example belongs to the Aspose.BarCode generation and recognition category, showcasing how to customize barcode appearance with BarColor and BackColor properties and adjust reader quality settings for improved detection. It uses BarcodeGenerator, BarCodeReader, and related parameter classes, useful for developers needing high‑contrast barcodes in varied lighting conditions.
// Prompt: Apply a custom color scheme to enhance detection of dark barcodes on light backgrounds.
// Tags: code128, color, generation, png, aspose.barcode, aspose.drawing
// Tags: barcode symbology, generation, recognition, custom colors, code128, png, aspose.barcode

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

/// <summary>
/// Example program that generates a Code128 barcode with a custom dark bar color
/// and a light background to enhance contrast for detection on light surfaces.
/// Example program that creates a barcode with a custom color scheme and then reads it back.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application. Creates a barcode, applies custom colors,
/// and saves the result as a PNG image.
/// Entry point of the application.
/// Generates a Code128 barcode with dark bars on a light background, saves it as PNG,
/// and then uses BarCodeReader to detect and display the barcode information.
/// </summary>
static void Main()
{
// Initialize a barcode generator for Code128 with the sample text "Sample123"
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample123"))
// Define the output file path for the generated barcode image.
string imagePath = "custom_color_barcode.png";

// Create a barcode generator for Code128 symbology with the desired text.
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "DarkOnLight"))
{
// Set a dark bar color (dark blue) to stand out against a light background
generator.Parameters.Barcode.BarColor = Color.FromArgb(0, 0, 139); // DarkBlue
// Set the bar (foreground) color to a dark shade.
generator.Parameters.Barcode.BarColor = Color.DarkBlue;

// Set a light background color (light yellow) to improve contrast
generator.Parameters.BackColor = Color.FromArgb(255, 255, 224); // LightYellow
// Set the background color to a light shade for high contrast.
generator.Parameters.BackColor = Color.LightYellow;

// Optional: increase XDimension for larger modules, improving readability
// Optional: increase the module (X) dimension for better visibility.
generator.Parameters.Barcode.XDimension.Point = 2f;

// Save the generated barcode image to a PNG file
generator.Save("custom_color_barcode.png");
// Save the generated barcode image in PNG format.
generator.Save(imagePath, BarCodeImageFormat.Png);
}

// Verify that the barcode image file was successfully created.
if (!File.Exists(imagePath))
{
Console.WriteLine($"Failed to create barcode image at '{imagePath}'.");
return;
}

// Inform the user that the barcode has been generated
Console.WriteLine("Barcode generated with custom colors: custom_color_barcode.png");
// Initialize a barcode reader to recognize any supported barcode type in the image.
using (var reader = new BarCodeReader(imagePath, DecodeType.AllSupportedTypes))
{
// Enhance detection settings for dark bars on a light background.
reader.QualitySettings.Deconvolution = DeconvolutionMode.Fast;
reader.QualitySettings.AllowIncorrectBarcodes = true;

// Iterate through all detected barcodes and output their details.
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"Detected Type: {result.CodeType}");
Console.WriteLine($"Detected Text: {result.CodeText}");

// Display the region (bounding rectangle) where the barcode was found.
var bounds = result.Region.Rectangle;
Console.WriteLine($"Region: X={bounds.X}, Y={bounds.Y}, Width={bounds.Width}, Height={bounds.Height}");
}
}
}
}
Loading
Loading