locked
WriteableBitmap and Image Flickering on update RRS feed

  • Question

  • I am using .NET 3.5 SP1, using a WriteableBitmap that is the source for an Image.

    What I'm noticing is that whenever I update my WriteableBitmap, I'm getting screen flashes.

    I only have one single call to WritePixels.  I have also tried locking using the BackBuffer and got the same results.

    I slowed the updates down to once per second and I can see the flash each time it updates.

    I've tried both re-assigning the Source property of the image each time as well as only assigning the Source once.

    I've also tried ping-ponging between two WriteableBitmaps.

    When updating, my CPU utilization is pretty much zero.

    I'm running on XP, but I tested it on Vista and had the same results.

    The reason the flicker is obvious is that my WritableImage is scrolling.  It is a data display where the data is drawn on the WriteableImage in a downward scrolling fashion (so the newest data is always on top).  However, I tried changing it so that it just changed the background color to something radically different and the flicker is still obvious.

    This size of the bitmap is irrelevant.  The flashing is just as obvious at 100x100 as it is at 1000x1000.

    It is also not simply flashing to the background color then updating.  Remember that this is scrolling downward, so each row will be a copy of the one above it.  If there is a section that is a solid vertical bar, it does not show the flicker.  However, if every other row is a black line, the flicker is painfully obvious.  It's almost as if I'm first seeing a double-image, then the final image.  I tried changing to a non-transparent PixelFormat but that didn't work either.  It can't be an anti-aliasing thing either, because at once per second the image wouldn't flash (it would just change and stick until the next update).

    Basically it appears that Image is not being double-buffered.  I clearly see the "update wave" on the image, which is causing the flicker.  It's not cleared to background first, but it's still being updated manually rather than backbuffered and switched.

    At 30 frames per second it'll give you some serious eye-strain.  Any help would be appreciated.
    Friday, March 20, 2009 5:43 PM

Answers

  • WriteableBitmap should be double buffered in 3.5SP1, however, on XP the screen itself isn't double buffered so you can still get tearing.  On Vista with the DWM (Aero glass) on you shouldn't see any tearing.  It's hard to tell from the description if that is the problem, but if you're seeing this on Vista I would think it's something else.

    Can you provide more information about your environment so we can try to reproduce it?  What video card are you using?  Are you running in Software or Hardware rendering mode (WPF perf tool in the Windows SDK will tell you this)?  Can you post some code with how you're using WriteableBitmap?

    Thanks,
    Brandon 
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Tao Liang Wednesday, March 25, 2009 3:30 AM
    Friday, March 20, 2009 10:23 PM