我正在使用WPF中的WriteableBitmap實現寬帶聲納顯示。 寬帶聲納'瀑布'顯示屏從頂部開始,隨着時間的推移,歷史數據向下移動,第一個'行'顯示當前情況。WPF:如果位圖頻繁更新,則呈現WriteableBitmap的最佳方法
從技術上講,我首先將位圖的內容與WriteableBitmap.CopyPixels()一起移除,之後我更新數組以更新顯示的當前行(頂部)。
我的問題是現在 - 在更新位圖 - 屏幕閃爍。我試圖寫我自己的WritePixels實現:
public static unsafe void WritePixels(WriteableBitmap writeableBitmap, BitmapProperties bitmapProperties)
{
writeableBitmap.Lock();
IntPtr buff = writeableBitmap.BackBuffer;
byte* pbuff = (byte*)buff.ToPointer();
for (int i = 0; i < bitmapProperties.BitmapArray.Length; i += bitmapProperties.BytesPerPixel)
{
pbuff[i] = bitmapProperties.BitmapArray[i];
pbuff[i + 1] = bitmapProperties.BitmapArray[i + 1];
pbuff[i + 2] = bitmapProperties.BitmapArray[i + 2];
pbuff[i + 3] = bitmapProperties.BitmapArray[i + 3];
}
writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, (int)writeableBitmap.Width, (int)writeableBitmap.Height));
writeableBitmap.Unlock();
}
不幸的是,ouctome是相同的。
我在這裏看到一些類似的問題(實現醫療超聲波顯示),但這裏的用例略有不同,因爲我沒有從第三方c + +接口的圖片,但我'繪製'並複製位圖我自己(更改/複製位圖數組)。 渲染(位圖的更新)應該每〜250毫秒進行一次。
我最好的選擇是什麼......使用緩存的位圖?對於WPF中的低級位圖操作(我正在使用WPF 4.5),我沒有太多經驗。
謝謝。
編輯:我將它與一個參考應用程序,用C++/DirectX編寫的比較:令我驚訝的是,我看到'閃爍'即使發生。這可能是一些光學效應,令人不安的眼睛等。但是,這個問題仍然有效,是否有比我目前的實施更好的方法。
是的,有想過這一點,但還沒有嘗試過,但。稍後會嘗試優化它... – Marco
爲什麼downvote? – tobsen