我的程序將位圖幀作爲視頻繪製到WPF控件。WPF:繪製位圖 - 訪問衝突?
的示例代碼如下:
while(true)
{
mStream = gcnew UnmanagedMemoryStream((unsigned char*)jpegBuff, jpegBuffLenght);
JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(mStream, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
bitmapSource = decoder->Frames[0];
myWPFControl.DrawImage(bitmapSource)
}
我遇到了兩個問題,我的代碼:
1)有時與消息"Insufficient memory to continue the execution of the program"
崩潰時在線路JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(...)
2運行)有時它與消息「訪問衝突」崩潰,並且在這種情況下的調用棧如下:
有人可以告訴我在我的代碼中的問題。
非常感謝!
牛逼&牛逼
圖像有多大?也是這意味着被標記'C++'不''c#' – 2014-10-01 03:49:21
@ sa_ddam213:我正在使用託管代碼。此圖像是1280x720,大小約2,7MB /幀 – TTGroup 2014-10-01 03:53:27
我不知道它是否有幫助,但我認爲您應該在每個循環結束時關閉UnmanagedMemoryStream。 – Fratyx 2014-10-01 05:11:56