Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: How do I prevent tearing with WriteableBitmap?
    text
    copied!<p>I'm using a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx" rel="nofollow noreferrer"><code>WriteableBitmap</code></a> to display images I process myself at around 20 frames per second.</p> <p>This question (<a href="https://stackoverflow.com/questions/893324/wpf-more-efficient-way-of-displaying-quickly-changing-images">WPF: More efficient way of displaying quickly-changing images?</a>)<br> and this question (<a href="https://stackoverflow.com/questions/812288/how-to-display-quick-updating-images-without-large-memory-allocation">How to display quick-updating images without large memory allocation?</a>)<br> indicate that the best way to do this is by using a <code>WriteableBitmap</code>.</p> <p>The documentation for <code>WriteableBitmap</code> indicates that calling <code>WritePixels()</code> on the UI thread will cause the rendering thread to redraw the image: </p> <p><strong>MSDN documentation:</strong><br> <em>The UI thread writes content to the back buffer. The render thread reads content from the front buffer and copies it to video memory. Changes to the back buffer are tracked with changed rectangular regions.</em> </p> <p><em>&lt; snip / ></em></p> <p><em>When updates are sent to the rendering thread, the rendering thread copies the changed rectangles from the back buffer to the front buffer. The rendering system controls this exchange to avoid deadlocks and redraw artifacts, such as "tearing".</em> </p> <p>I process my images on a background thread, then use <code>Dispatcher.BeginInvoke()</code> to call <code>WritePixels()</code>, to ensure that <code>WritePixels()</code> is called on the UI thread.</p> <p>I'm finding that tearing still occurs with <code>WriteableBitmap</code>, and in the application I'm working on, it looks awful (its a medical imaging application). Is there anything I can do?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload