2013-08-07 3 views
0

Я пытаюсь разработать простое приложение, в котором загружаю видеофайл, а затем отображать его на моем экране по кадре.AForge.Video.DirectShow bitmap arg 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

Конструктор Bitmap, кажется, не залили значения.

Любая идея о том, почему видео не загружается нормально?

Спасибо за помощь!

ответ

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