我有一個程式,我在其中使用 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 中進行。
謝謝
uj5u.com熱心網友回復:
不確定這是否有幫助,但您是否嘗試過將 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();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/532975.html
