Scan and read QR codes in C#

Nutrient .NET SDK (formerly GdPicture.NET) enables you to recognize one-dimensional (1D or linear) and two-dimensional (2D) barcodes.

Nutrient .NET SDK supports all 1D barcode formats and the following 2D barcode formats:

  • Aztec Code
  • Data Matrix
  • MaxiCode
  • Micro QR
  • PDF417
  • QR

To recognize QR barcodes and then write their values to the console, follow these steps:

  1. Create a GdPictureImaging object.
  2. Select the image by passing its path to the CreateGdPictureImageFromFile method of the GdPictureImaging object.
  3. Scan the barcodes by passing the image as the parameter of the BarcodeQRReaderDoScan method.
  4. Determine the number of scanned barcodes and loop through them.
  5. Save the value of each barcode.
  6. Write the values to the console.
  7. Release unnecessary resources.

The example below scans QR barcodes and then writes their values to the console:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Select the image to process.
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.png");
// Scan the barcodes.
gdpictureImaging.BarcodeQRReaderDoScan(imageID);
// Determine the number of scanned barcodes.
int barcodeCount = gdpictureImaging.BarcodeQRReaderGetBarcodeCount();
string content = "";
if (barcodeCount > 0)
{
content = "Number of barcodes scanned: " + barcodeCount.ToString();
// Save the value of each barcode.
for (int i = 1; i <= barcodeCount; i++)
{
content += $"\nBarcode Number: {i} Value: {gdpictureImaging.BarcodeQRReaderGetBarcodeValue(i)}";
}
}
// Write the values to the console.
Console.WriteLine(content);
// Release unnecessary resources.
gdpictureImaging.BarcodeQRReaderClear();
gdpictureImaging.ReleaseGdPictureImage(imageID);

Additional options

To determine the version of a QR barcode, pass the index of the barcode to the BarcodeQRReaderGetVersion method.