2013-08-07 47 views
0

我想开发一个简单的应用程序,我加载一个视频文件,然后逐帧显示在我的屏幕上。AForge.Video.DirectShow位图参数ArgumentException

加载视频文件,我用这个代码:

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(所以excplicit ...)。如果我在fileVideo停止调试,我可以看到这一点:

enter image description here

位图似乎没有填充值。

任何想法,为什么视频不加载罚款?

感谢您的帮助!

回答

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(); 
}