【问题标题】:How to use the Zxing barcode scanner library along with the Aforge webcam library如何使用 Zxing 条码扫描器库和 Aforge 网络摄像头库
【发布时间】:2022-11-14 11:14:46
【问题描述】:

我有一个程序,我在其中使用 Aforge 库来查看网络摄像头。 这很神奇:

LocalWebcamsCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
LocalScannerBarcode = new VideoCaptureDevice(LocalWebcamsCollection[WebcamNumber].MonikerString);
LocalScannerBarcode.NewFrame += LocalScannerBarcode_NewFrame;
LocalScannerBarcode.Start();

在新的帧事件中我得到位图

System.Drawing.Bitmap frame;    
void LocalScannerBarcode_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
    frame = (System.Drawing.Bitmap)eventArgs.Frame.Clone();
}

现在我必须解码所看到的。基本上我必须通过位图来解码。 所以我有全球性;

ZXing.BarcodeReader bcr;

并进入事件 LocalScannerBarcode_NewFrame

if (bcr == null)
        bcr = new ZXing.BarcodeReader();

但是一旦我把这两行放在上面,就不再调用事件了。

请注意,在 Windows 表单中有效,但我必须在 WPF 中进行。

谢谢

【问题讨论】:

    标签: c# wpf barcode webcam barcode-scanner


    【解决方案1】:

    不确定这是否有帮助,但您是否尝试过将 ZXing 库的引用放在另一个项目中?一个助手的东西。

    因此,在您的项目中,您将拥有:

    string strResult = Helper.ReadBarcode(frame);
    if (strResult != null)
    {
                ... do stuff with the string
    }
    

    并在助手中

    static ZXing.BarcodeReader bcr;
    public static string ReadBarcode(System.Drawing.Bitmap bmp)
    {
        if (bcr == null)
            bcr = new ZXing.BarcodeReader();
        return bcr.Decode(bmp).ToString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-22
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多