我正在嘗試編寫一段代碼,它將視頻捕獲設備的前一幀更新爲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)
{
}
}