本文介绍如何使用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
二维码数据读取结果: