Skip to content

Commit 7fe9127

Browse files
author
agent-aspose-barcode-examples
committed
Add generated examples for swiss-qr-code
1 parent 43c1a3a commit 7fe9127

4 files changed

Lines changed: 172 additions & 0 deletions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using Aspose.BarCode.Generation;
5+
using Aspose.BarCode.BarCodeRecognition;
6+
using Aspose.BarCode.ComplexBarcode;
7+
8+
class Program
9+
{
10+
static void Main()
11+
{
12+
// Define resolutions (DPI) to test
13+
float[] resolutions = { 72f, 150f, 300f, 600f };
14+
15+
// Prepare Swiss QR bill data (same for all images)
16+
var swissQr = new SwissQRCodetext();
17+
swissQr.Bill.Creditor.Name = "John Doe";
18+
swissQr.Bill.Creditor.CountryCode = "CH";
19+
swissQr.Bill.Account = "CH9300762011623852957";
20+
swissQr.Bill.Amount = 199.95m;
21+
swissQr.Bill.Version = SwissQRBill.QrBillStandardVersion.V2_0;
22+
23+
Console.WriteLine("Benchmark: Decoding Swiss QR Code images at various resolutions");
24+
Console.WriteLine();
25+
26+
foreach (float dpi in resolutions)
27+
{
28+
// Generate barcode image at specified resolution
29+
using (var generator = new ComplexBarcodeGenerator(swissQr))
30+
{
31+
generator.Parameters.Resolution = dpi;
32+
33+
using (var imageStream = new MemoryStream())
34+
{
35+
generator.Save(imageStream, BarCodeImageFormat.Png);
36+
imageStream.Position = 0; // Reset for reading
37+
38+
// Measure decoding time
39+
var stopwatch = Stopwatch.StartNew();
40+
41+
using (var reader = new BarCodeReader(imageStream, DecodeType.AllSupportedTypes))
42+
{
43+
// Read all barcodes (there should be one Swiss QR)
44+
foreach (var result in reader.ReadBarCodes())
45+
{
46+
// Access result to ensure decoding occurs
47+
var codeText = result.CodeText;
48+
}
49+
}
50+
51+
stopwatch.Stop();
52+
Console.WriteLine($"Resolution: {dpi} DPI - Decode time: {stopwatch.ElapsedMilliseconds} ms");
53+
}
54+
}
55+
}
56+
57+
Console.WriteLine();
58+
Console.WriteLine("Benchmark completed.");
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode;
4+
using Aspose.BarCode.ComplexBarcode;
5+
using Aspose.BarCode.Generation;
6+
using Aspose.Drawing;
7+
8+
class Program
9+
{
10+
static void Main()
11+
{
12+
// Prepare SwissQR codetext with mandatory fields
13+
var swissQr = new SwissQRCodetext();
14+
swissQr.Bill.Creditor.Name = "John Doe";
15+
swissQr.Bill.Creditor.CountryCode = "CH";
16+
swissQr.Bill.Account = "CH9300762011623852957";
17+
swissQr.Bill.Amount = 199.95m;
18+
swissQr.Bill.Version = SwissQRBill.QrBillStandardVersion.V2_0;
19+
20+
// Create ComplexBarcodeGenerator with the codetext
21+
using (var generator = new ComplexBarcodeGenerator(swissQr))
22+
{
23+
// Set transparent background for overlay use
24+
generator.Parameters.BackColor = Aspose.Drawing.Color.Transparent;
25+
26+
// Optional: set QR error correction level to high
27+
generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH;
28+
29+
// Save the barcode image as PNG (supports transparency)
30+
string outputPath = "transparent_swissqr.png";
31+
generator.Save(outputPath, BarCodeImageFormat.Png);
32+
Console.WriteLine($"Barcode saved to {Path.GetFullPath(outputPath)}");
33+
}
34+
}
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.IO;
3+
using Aspose.BarCode.ComplexBarcode;
4+
using Aspose.BarCode.Generation;
5+
6+
class Program
7+
{
8+
// Generates a Swiss QR Code PNG and returns it as a byte array.
9+
// Required fields: Creditor Name, Creditor CountryCode, Account (IBAN), Amount, Version.
10+
public static byte[] CreateSwissQrCode(string creditorName, string creditorCountryCode, string account, decimal amount)
11+
{
12+
// Build the Swiss QR codetext with mandatory bill data.
13+
var swissQr = new SwissQRCodetext();
14+
swissQr.Bill.Creditor.Name = creditorName;
15+
swissQr.Bill.Creditor.CountryCode = creditorCountryCode;
16+
swissQr.Bill.Account = account;
17+
swissQr.Bill.Amount = amount;
18+
swissQr.Bill.Version = SwissQRBill.QrBillStandardVersion.V2_0;
19+
20+
// Generate the barcode image and save it to a memory stream as PNG.
21+
using (var generator = new ComplexBarcodeGenerator(swissQr))
22+
{
23+
using (var memoryStream = new MemoryStream())
24+
{
25+
generator.Save(memoryStream, BarCodeImageFormat.Png);
26+
return memoryStream.ToArray();
27+
}
28+
}
29+
}
30+
31+
static void Main()
32+
{
33+
// Sample data (valid IBAN and creditor details).
34+
string name = "John Doe";
35+
string countryCode = "CH";
36+
string iban = "CH9300762011623852957";
37+
decimal amount = 199.95m;
38+
39+
byte[] pngBytes = CreateSwissQrCode(name, countryCode, iban, amount);
40+
Console.WriteLine($"Generated Swiss QR Code PNG byte array length: {pngBytes.Length}");
41+
// Optionally write to a file for verification (commented out to avoid I/O in the runner).
42+
// File.WriteAllBytes("SwissQR.png", pngBytes);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Aspose.BarCode.Generation;
3+
using Aspose.BarCode.ComplexBarcode;
4+
using Aspose.BarCode;
5+
6+
namespace BarcodeExample
7+
{
8+
class Program
9+
{
10+
static void Main()
11+
{
12+
// Create Swiss QR bill data
13+
var swissQr = new SwissQRCodetext();
14+
swissQr.Bill.Creditor.Name = "John Doe";
15+
swissQr.Bill.Creditor.CountryCode = "CH";
16+
swissQr.Bill.Account = "CH9300762011623852957";
17+
swissQr.Bill.Amount = 199.95m;
18+
swissQr.Bill.Version = SwissQRBill.QrBillStandardVersion.V2_0;
19+
20+
// Initialize ComplexBarcodeGenerator with the codetext
21+
using (var generator = new ComplexBarcodeGenerator(swissQr))
22+
{
23+
// Set high error correction level for QR code
24+
generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH;
25+
26+
// Save the generated Swiss QR code image
27+
generator.Save("SwissQR.png");
28+
}
29+
30+
Console.WriteLine("Swiss QR code generated with high error correction level.");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)