为什么网络摄像机在一定时间后冻结

时间:2018-07-19 06:45:30

标签: c# wpf aforge

我编写了一个具有可扫描QR码的网络摄像头的应用程序:

VideoCaptureDevice LocalWebCam;
public FilterInfoCollection LoaclWebCamsCollection;

void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    try
    {
        BitmapImage bi;
        using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
        {
            bi = new BitmapImage();
            bi.BeginInit();
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, ImageFormat.Bmp);
            bi.StreamSource = ms;
            bi.CacheOption = BitmapCacheOption.OnLoad;
            bi.EndInit();
        }
        bi.Freeze();
        Dispatcher.BeginInvoke(new ThreadStart(delegate { frameHolder.Source = bi; }));
    }
    catch
    {
        //some error
    }

void Window2_Loaded(object sender, RoutedEventArgs e)
{
    LoaclWebCamsCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
    LocalWebCam = new VideoCaptureDevice(LoaclWebCamsCollection[0].MonikerString);
    LocalWebCam.NewFrame += new NewFrameEventHandler(Cam_NewFrame);
    LocalWebCam.Start();
    timer.Start(); // QR CODE SCANNER
}

一切正常但是,当我让应用程序运行更长的时间时,webam会冻结。有人知道为什么吗?

0 个答案:

没有答案