BarCode Reader SDK使用教程:如何从图像中读取条码

我们知道很多语言都可以在windows平台上读取条码,今天将分享在BarCode Reader SDK中如何用VB.NET或者C#来读取图像中的条码。

这段代码演示了如何从图像中读取条码及打印到输出控制台。

Visual Basic .NET:

Imports System.IO

Imports Bytescout.BarCodeReader ' requiring to install evaluation or full version of Barcode Reader SDK

<em>Module <font class="Apple-style-span" color="#000000"><span data-scayt_word="Module1" data-scayt>Module1</span></font></em>

Sub Main()

Dim pat As String = "InputPhoto.jpg"

Console.WriteLine("Reading barcode(s) from image {0}", Path.GetFullPath(pat))

Dim <span data-scayt_word="bc" data-scayt>bc</span> As New Reader()

bc.TypeToFind = SymbologyFilter.FindAll

Dim barcodes As <span data-scayt_word="FoundBarcode" data-scayt>FoundBarcode</span>() = bc.ReadFrom(pat)

Dim i As Integer

For i = 0 To barcodes.Length - 1

Console.WriteLine("Found barcode with type '{0}' and value '{1}'", barcodes(i).Type, barcodes(i).Value)

Next

Console.WriteLine("Press any key to exit..")

Console.ReadKey()

End Sub

End Module

  

C#

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using Bytescout.BarCodeReader; // requires to have evaluation or full version of Barcode Reader SDK installed

<span data-scayt_word="namespace" data-scayt>SimpleTestSharp</span>

{

class Program

{

<span data-scayt_word="const" data-scayt;

static void Main(string[] <span data-scayt_word="args" data-scayt>args</span>)

{

Console.WriteLine("Reading barcode(s) from image {0}", Path.GetFullPath(path));

Reader <span data-scayt_word="bc" data-scayt>bc</span> = new Reader();

<span data-scayt_word="FoundBarcode" data-scayt>FoundBarcode</span>[] barcodes = bc.ReadFrom(path);

<span data-scayt_word="foreach" data-scayt>FoundBarcode</span> barcode in barcodes)

Console.WriteLine("Found barcode with type '{0}' and value '{1}'", barcode.Type, barcode.Value);

Console.WriteLine("Press any key to exit..");

Console.ReadKey();

}

}

}

  

本文译自BarCode Reader