【发布时间】:2017-12-11 20:28:02
【问题描述】:
我正在尝试开发一个 WindowsForm 应用程序,它将使用网络摄像头检测 QRCode 并解码消息。为此,我使用 AForge.NET 和 ZXing.NET。
到目前为止,我已经能够弄清楚如何从 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;
}
}
【问题讨论】:
-
也许您需要捕获相机图像,然后调用解码库