我正在尝试开发一个WindowsForm应用程序,它将使用网络摄像头来检测QRCode并解码消息。为此,我正在使用AForge.NET和ZXing.NET。
到目前为止,我已经能够弄清楚如何从URI解码QRCode,但我想检测来自网络摄像头的QRCode并解码它。
以下是我的代码示例。
到目前为止,我已经能够弄清楚如何从URI解码QRCode,但我想检测来自网络摄像头的QRCode并解码它。
以下是我的代码示例。
public String Decode(Uri uri)
{
Bitmap image;
try
{
image = (Bitmap)Bitmap.FromFile(uri.LocalPath);
}
catch (Exception ex)
{
throw new FileNotFoundException("Resource not found: " + uri);
}
using (image)
{
String text = "";
LuminanceSource source = new BitmapLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
if (result != null)
{
text = result.Text;
return text;
}
text = "Provided QR couldn't be read.";
return text;
}
}