WPF:如何防止 WriteableBitmap 撕裂?

发布于 2024-07-25 02:54:04 字数 1199 浏览 5 评论 0原文

我正在使用 WriteableBitmap< /code>来显示图像,我自己处理的速度约为每秒 20 帧。

这个问题(WPF:更有效地显示快速变化图像的方法?)
和这个问题(How to display fast-updating images without大内存分配?
表明执行此操作的最佳方法是使用 WriteableBitmap

WriteableBitmap 的文档表明,在 UI 线程上调用 WritePixels() 将导致渲染线程重绘图像:

MSDN 文档:
UI 线程将内容写入后台缓冲区。 渲染线程从前端缓冲区读取内容并将其复制到视频内存。 后台缓冲区的更改通过更改的矩形区域进行跟踪。

< snip / >

当更新发送到渲染线程时,渲染线程将更改的矩形从后台缓冲区复制到前台缓冲区。 渲染系统控制此交换,以避免死锁和重绘伪像,例如“撕裂”。

我在后台线程上处理图像,然后使用 Dispatcher.BeginInvoke() 调用 WritePixels(),以确保在 UI 线程上调用 WritePixels()

我发现 WriteableBitmap 仍然会出现撕裂,并且在我正在开发的应用程序中,它看起来很糟糕(它是一个医学成像应用程序)。 有什么我可以做的吗?

I'm using a WriteableBitmap to display images I process myself at around 20 frames per second.

This question (WPF: More efficient way of displaying quickly-changing images?)
and this question (How to display quick-updating images without large memory allocation?)
indicate that the best way to do this is by using a WriteableBitmap.

The documentation for WriteableBitmap indicates that calling WritePixels() on the UI thread will cause the rendering thread to redraw the image:

MSDN documentation:
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.

< snip / >

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".

I process my images on a background thread, then use Dispatcher.BeginInvoke() to call WritePixels(), to ensure that WritePixels() is called on the UI thread.

I'm finding that tearing still occurs with WriteableBitmap, and in the application I'm working on, it looks awful (its a medical imaging application). Is there anything I can do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-08-01 02:54:04

为了避免撕裂,WriteableBitmap 投入了大量工作,但在某些系统配置上这是不可避免的。 这主要发生在关闭了 Aero (DWM) 的 Windows XP 或 Vista 上。

There was a lot of work put into WriteableBitmap to avoid tearing, but on some system configurations this is unavoidable. This mostly will happen on Windows XP or Vista w/ Aero (DWM) turned off.

过度放纵 2024-08-01 02:54:04

当您调用 WritePixels() 时,您可能会覆盖位图。 使用 Dispatcher.Invoke() 而不是 BeginInvoke() 可能会有所帮助。

While you are calling WritePixels() you may be overwriting your bitmap. Using Dispatcher.Invoke() rather then BeginInvoke() might help.

长发绾君心 2024-08-01 02:54:04

我知道这是一个旧线程,但我们遇到了完全相同的问题,在我们的例子中,它是由使用 Dispatcher.BeginInvoke 调用我们的更新显示方法引起的 - 当我们更改为 Dispatcher.Invoke 时,它​​立即消失了。

I know this is an old thread but we had exactly the same issue and in our case it was caused by calling our update display method using Dispatcher.BeginInvoke - the moment we changed to Dispatcher.Invoke it cleared up instantly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文