AForge.Video.DirectShow位图arg ArgumentException

时间:2013-08-07 14:34:56

标签: directshow aforge imaging

我正在尝试开发一个简单的应用程序,我加载一个视频文件,然后逐帧显示在我的屏幕上。

要加载视频文件,请使用以下代码:

FileVideoSource fileVideo = new FileVideoSource(myVideoSource);
fileVideo.NewFrame += fileVideo_NewFrame;
fileVideo.Start();

然后,在fileVideo_NewFrame,我像这样捕捉每一帧:

 if (SynchronizationContext.Current != uiContext)
 {
        uiContext.Post(delegate { fileVideo_NewFrame(sender, eventArgs);}, null);
        return;
 }

 Bitmap bitmap = eventArgs.Frame;
 PictureBoxvideo.Image = new Bitmap(bitmap);

 bitmap.Dispose();

但是我收到了System.ArgumentException(所以很明显......)。如果我在fileVideo停止调试,我可以看到:

enter image description here

Bitmap似乎没有填充值。

为什么视频没有正常加载?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我可以使用here发布的解决方案来解决这个问题。

FileVideoSource fileVideo = new FileVideoSource(dialog.FileName);
AsyncVideoSource asyncVideoSource = new AsyncVideoSource(fileVideo);
asyncVideoSource.NewFrame += asyncVideoSource_NewFrame;
asyncVideoSource.Start();

private void asyncVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    Image temp = PictureBoxvideo.Image;
    Bitmap bitmap = eventArgs.Frame;
    PictureBoxvideo.Image = new Bitmap(bitmap);
    if (temp!= null) temp.Dispose();
    bitmap.Dispose();
}