-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-image-from-azure-blob-storage-and-extract-barcode-type-and-code-text.cs
More file actions
68 lines (63 loc) · 2.75 KB
/
Copy pathfetch-image-from-azure-blob-storage-and-extract-barcode-type-and-code-text.cs
File metadata and controls
68 lines (63 loc) · 2.75 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
// Title: Read barcode from image (local fallback)
// Description: Demonstrates fetching an image (placeholder for Azure Blob) and extracting barcode type and text using Aspose.BarCode.
// Prompt: Fetch image from Azure Blob storage and extract barcode type and code text.
// Tags: barcode symbology, read, console, aspose.barcode, azure blob
using System;
using System.IO;
using Aspose.BarCode.Generation;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.Drawing;
/// <summary>
/// Example program that reads barcodes from an image.
/// In a real scenario the image would be downloaded from Azure Blob storage,
/// but this demo uses a local file as a fallback.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application.
/// Loads an image, scans for barcodes, and prints their type and text.
/// </summary>
static void Main()
{
// NOTE: In a real environment you would download the image from Azure Blob Storage
// using Azure.Storage.Blobs. The required SDK is not available in the snippet runner,
// so the code is provided as a comment for reference.
/*
// Real Azure Blob download (requires Azure.Storage.Blobs NuGet package)
string connectionString = "<your_connection_string>";
string containerName = "<your_container_name>";
string blobName = "<your_blob_name>";
var blobClient = new BlobClient(connectionString, containerName, blobName);
using (var downloadStream = new MemoryStream())
{
blobClient.DownloadTo(downloadStream);
downloadStream.Position = 0;
// Proceed with barcode reading using the stream
}
*/
// Fallback: use a local image file for demonstration
string localImagePath = "sample.png";
// Verify that the image file exists before proceeding
if (!File.Exists(localImagePath))
{
Console.WriteLine($"Image file not found: {localImagePath}");
return;
}
// Load the image into a Bitmap (Aspose.Drawing)
using (Bitmap bitmap = new Bitmap(localImagePath))
{
// Initialize the barcode reader with the bitmap and enable all supported types
using (BarCodeReader reader = new BarCodeReader(bitmap, DecodeType.AllSupportedTypes))
{
// Iterate through detected barcodes
foreach (BarCodeResult result in reader.ReadBarCodes())
{
// Output the barcode type (e.g., QR, Code128) and its decoded text
Console.WriteLine($"BarCode Type: {result.CodeTypeName}");
Console.WriteLine($"BarCode CodeText: {result.CodeText}");
}
}
}
}
}