I'm currently implementing a broadband sonar display by using WriteableBitmap in WPF. A broadband sonar 'waterfall' display starts at the top and as time moves, the history data moves down and the first 'row' displays always the current situation.
Technically, I first move the content of the Bitmap down with WriteableBitmap.CopyPixels(), afterwards I update the Array to update the current line (top) of the Display.
My problem is now that - during update of the bitmap - the screen flickers. I've tried to write my own implementation of 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();
}
Unfortunately the ouctome is the same.
I've seen here some similar questions (implementing a medical ultrasonic-display) but the usecase here is slightly different, since I get not the picture from a third party c++ interface but I 'draw' and copy the bitmap by myself (altering/copying the bitmap-array). The rendering (update of the bitmap) shall take place every ~ 250 milliseconds.
What would my best choice here...working with a cached bitmap? I have not much experience when it comes to low-level bitmap operations in WPF (I am using WPF 4.5).
Thanks.
EDIT: I've compared it with a reference application, written in C++/DirectX: To my astonishment, I see the 'flickering' even there happening. It might be some optical effects, disturbing the eyes etc. Nevertheless, the question is still valid concerning if there is a better approach than my current implementation.