-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplement-method-that-resets-all-qualitysettings-to-defaults-before-processing-new-image-batch.cs
More file actions
87 lines (78 loc) · 3 KB
/
Copy pathimplement-method-that-resets-all-qualitysettings-to-defaults-before-processing-new-image-batch.cs
File metadata and controls
87 lines (78 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.Drawing;
/// <summary>
/// Demonstrates generating a barcode image, reading it back, and cleaning up temporary files.
/// </summary>
class Program
{
/// <summary>
/// Resets all QualitySettings of the provided <see cref="BarCodeReader"/> to their default values.
/// </summary>
/// <param name="reader">The barcode reader whose quality settings will be reset.</param>
static void ResetQualitySettings(BarCodeReader reader)
{
// Default: do not allow incorrect barcodes.
reader.QualitySettings.AllowIncorrectBarcodes = false;
// Default quality mode (assumed Normal). Adjust if a different default is required.
reader.QualitySettings.BarcodeQuality = BarcodeQualityMode.Normal;
}
/// <summary>
/// Entry point of the application. Generates a sample barcode, reads it, and performs cleanup.
/// </summary>
static void Main()
{
// Prepare a temporary folder for generated barcode images.
string tempDir = Path.Combine(Path.GetTempPath(), "AsposeBarcodeDemo");
if (!Directory.Exists(tempDir))
{
Directory.CreateDirectory(tempDir);
}
// Generate a sample barcode (Code128) to be used in the batch.
string barcodePath = Path.Combine(tempDir, "sample.png");
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890"))
{
// Use default settings; save as PNG.
generator.Save(barcodePath);
}
// Simulate a small batch of image files containing barcodes.
string[] imageBatch = new string[] { barcodePath };
// Process each image in the batch.
foreach (var imagePath in imageBatch)
{
if (!File.Exists(imagePath))
{
Console.WriteLine($"File not found: {imagePath}");
continue;
}
// Create a BarCodeReader for the current image.
using (var reader = new BarCodeReader(imagePath, DecodeType.AllSupportedTypes))
{
// Reset quality settings before processing this image.
ResetQualitySettings(reader);
// Read and output all detected barcodes.
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"File: {Path.GetFileName(imagePath)}");
Console.WriteLine($"Detected Type: {result.CodeTypeName}");
Console.WriteLine($"Code Text: {result.CodeText}");
}
}
}
// Cleanup temporary files (optional).
try
{
if (File.Exists(barcodePath))
File.Delete(barcodePath);
if (Directory.Exists(tempDir))
Directory.Delete(tempDir, true);
}
catch
{
// Ignore cleanup errors.
}
}
}