Creating customizable QR codes is a powerful way to deliver links, IDs, and app-deep links while staying on brand. With Aspose.BarCode for .NET, you can fine-tune error correction, module sizing, colors, and output formats to meet both functional and aesthetic needs. This article aligns the step-by-step instructions with the gist at the end and adds practical tips, gotchas, and optional enhancements.
Prerequisites
- .NET 8 (or .NET 6+) SDK
- NuGet access (
Aspose.BarCode
) - Basic familiarity with
System.Drawing
- (Optional) High-resolution output target for print use cases
Create a project & add the package
dotnet new console -n CustomizableQRCodeExample -f net8.0
cd CustomizableQRCodeExample
dotnet add package Aspose.BarCode
Complete Example
using System;
using System.Drawing;
using Aspose.BarCode.Generation;
namespace CustomizableQRCodeExample
{
class Program
{
static void Main(string[] args)
{
// Step 1: Create a QR code generator with specific settings
var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, "https://www.aspose.com");
// Step 2: Configure QR code properties
qrGenerator.Parameters.Barcode.QR.CodeText = "https://www.aspose.com";
qrGenerator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevelLevel.High;
qrGenerator.Parameters.Barcode.QR.ModuleSize = 5;
qrGenerator.Parameters.Barcode.XDimension.Pixels = 2;
// Step 3: Customize colors
qrGenerator.Parameters.Barcode.ForegroundColor = Color.Black;
qrGenerator.Parameters.Barcode.BackgroundColor = Color.White;
// Step 4: Generate and save the QR code as an image
using (var image = qrGenerator.GenerateBarCodeImage())
{
image.Save("CustomQRCode.png");
Console.WriteLine("QR Code generated successfully!");
}
}
}
}
Step-by-Step (Mapped to the Example)
Step 1: Initialize the QR Generator
Create a generator with EncodeTypes.QR
and a default payload (URL, ID, etc.).
var qrGenerator = new BarcodeGenerator(EncodeTypes.QR, "https://www.aspose.com");
You can set the content either via the constructor or
Parameters.Barcode.QR.CodeText
. The example sets both for clarity.
Step 2: Configure Core QR Properties
- Code text: the actual data encoded in the QR.
- Error correction: controls resiliency (e.g., smudges, logos over the code).
- Module/Cell size: the size of each square “module”.
qrGenerator.Parameters.Barcode.QR.CodeText = "https://www.aspose.com";
qrGenerator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevelLevel.High; // robust against damage
qrGenerator.Parameters.Barcode.QR.ModuleSize = 5; // pixels per module (visual density)
qrGenerator.Parameters.Barcode.XDimension.Pixels = 2; // base module thickness (kept to match gist)
Note: For QR, setting
QR.ModuleSize
is typically sufficient. The example also setsXDimension.Pixels
to mirror the gist; if you tune just one, preferQR.ModuleSize
for predictable visual scaling.
Step 3: Apply Brand Colors (Foreground/Background)
qrGenerator.Parameters.Barcode.ForegroundColor = Color.Black;
qrGenerator.Parameters.Barcode.BackgroundColor = Color.White;
For maximum scan reliability, ensure adequate contrast. If you invert colors or place on busy backgrounds, add a generous quiet zone (margin).
Step 4: Render & Save
Generate a System.Drawing.Image
and save as PNG (sharp, lossless).
using (var image = qrGenerator.GenerateBarCodeImage())
{
image.Save("CustomQRCode.png");
}
Optional Enhancements
A) Export to Multiple Formats
using System.Drawing.Imaging;
// After GenerateBarCodeImage():
image.Save("CustomQRCode.jpg", ImageFormat.Jpeg); // for photos/CMYK workflows
image.Save("CustomQRCode.bmp", ImageFormat.Bmp); // uncompressed (big files)
B) Increase Print-Readiness
- Scale up: raise
QR.ModuleSize
(e.g., 6–10) for physical prints. - Quiet zone: ensure sufficient whitespace around the code; if your layout tool trims too close, add padding to the image.
- High error correction: keep
High
if placing small logos or printing on textured surfaces.
C) Embed Payload Variants
- App links:
myapp://open?id=12345
- Wi-Fi config:
WIFI:T:WPA;S:MySSID;P:MyPassword;H:false;
- vCard:
BEGIN:VCARD\nVERSION:3.0\nN:…\nEND:VCARD
Troubleshooting
- Scanner won’t read: Increase contrast (dark foreground, light background), grow
ModuleSize
, and ensure a clean quiet zone. - Blurry at small sizes: Avoid JPEG for tiny codes; prefer PNG and larger modules.
- Logo overlay: Keep it small and centered; rely on
High
error correction to compensate.
Best Practices
- Content validation: Validate URLs/IDs before embedding to avoid stale QR codes in print.
- Version control: Keep generator settings in code (or config) and commit them—reproducible outputs matter in branding.
- Environment parity: If you render on CI, use the same DPI/font stack to avoid subtle raster differences.
Conclusion
With Aspose.BarCode for .NET, you can create QR codes that are not only robust (via error correction) but also on-brand (via sizing and color control). Start from the complete example above and adjust ModuleSize
, error correction, and colors to fit your delivery medium—screen, label, or billboard.