2014-07-01 58 views
0

我正在嘗試編寫一段代碼,它將視頻捕獲設備的前一幀更新爲Image.Source在Visual Studio 2013中顯示BitmapSource的問題c#

我使用的是AForge.NET API:Aforge.Video and Aforge.Video.DirectShow。這一切似乎運行順利,但是當我更新我的Image.Source到當前幀圖像變爲空白。

您將在我的代碼中看到我在各種轉換後保存了位圖,這是爲了檢查位圖是否仍包含該幀。測試是成功的,即保存的圖像是非空白的。以下是我的代碼newFrameEvent,如果有人有任何想法,我會很感激!

newframeEvent參數是System.Drawing.Bitmap對象。

private void NewThermalFrameReady(object sender, NewFrameEventArgs e) 
{ 
    //Copy frame into tempoary storage. In format Bitmap   
    this.frame = e.Frame; 

    //Save Bitmap frame for test 
    this.frame.Save("C:/Users/Shankar/Documents/Visual Studio 
    2013/Projects/Capture_Devices/Capture_Devices/test.jpg"); 

    //Get BitmapSource from Bitmap and save to double check conversion was sucessful 
    this.finalFrame = Imaging.CreateBitmapSourceFromBitmap(frame); 
    CreateThumbnail("C:/Users/Shankar/Documents/Visual Studio 
    2013/Projects/Capture_Devices/Capture_Devices/test2.jpg", 
    this.finalFrame.Clone()); 

    try 
    { 
     this.Dispatcher.Invoke((Action)(() => 
     { 
      if (finalFrame!=null) 
      {      
       this.frameDisp.Source = this.finalFrame; 
      }  
     })); 
    } 
    catch (System.Threading.Tasks.TaskCanceledException) 
    { 

    } 


} 

回答

0

是不是總是這樣,你花了幾個小時問問題,然後最終解決它!我不得不移動:

this.finalFrame = Imaging.CreateBitmapSourceFromBitMap(frame); 

進入調度程序調用後,它的工作完美!我會在這裏留下的問題,以防萬一任何人有這個問題...

0

這對我來說,在圖片框顯示新的形象;

空隙videoSource_NewFrame(對象發件人,AForge.Video.NewFrameEventArgs EventArgs的) {

 pictureBoxVideo.BackgroundImage = (Bitmap)eventArgs.Frame.Clone(); 
    } 

所以可以嘗試使用;

 this.frame = e.Frame.Clone(); // in your code