本文介绍如何使用spire.barcode for .net来扫描并识别二维码图片中的数据,通过调用barcodescanner类提供的scan(bitmap image, barcode type barcodetype)方法实现。详细代码参考如下内容。
下图是用于测试的二维码图片:
c#
using spire.barcode;
using system.drawing;
namespace scanqrcode
{
class program
{
static void main(string[] args)
{
//加载二维码图片
image image = image.fromfile("qrcode.png");
bitmap bitmap = new bitmap(image);
//识别二维码图片中的数据
string[] data = barcodescanner.scan(bitmap, barcodetype.qrcode);
for (int i = 0; i < data.length; i )
{
string text = data[i].tostring();
system.console.writeline(text);
system.console.readline();
}
}
}
}
vb.net
imports spire.barcode
imports system.drawing
namespace scanqrcode
class program
private shared sub main(args as string())
'加载二维码图片
dim image__1 as image = image.fromfile("qrcode.png")
dim bitmap as new bitmap(image__1)
'识别二维码图片中的数据
dim data as string() = barcodescanner.scan(bitmap, barcodetype.qrcode)
for i as integer = 0 to data.length - 1
dim text as string = data(i).tostring()
system.console.writeline(text)
system.console.readline()
next
end sub
end class
end namespace
二维码数据读取结果: