在 WPF 中不断绘制大量位图的最佳方法?
我被这个非常简单的问题难住了。我正在制作一个基于图块的游戏引擎,需要能够允许用户使用 WPF 用户界面编辑地图。天真地,我以为我可以简单地使用 Graphics.FromImage 不断更新一个好的老式“缓冲”System.Drawing.Graphics.Bitmap。我会将构成地图的图块绘制到位图上,然后将缓冲区位图传输到屏幕。然而,根据我的深入研究,我现在相信这根本不是那么容易。
我不想让您厌倦我到目前为止所发现的内容(要么不起作用,要么非常慢),我可以简单地问一下,通过 WPF UI 有效地连续绘制大量位图的最佳方法是什么?
我会接受“回到Windows Forms”这样的建议。如果是这样的话,那我将对 WPF 非常失望!
I am stumped by this very simple problem. I am making a tile-based game engine and need to be able to allow a user to edit the map using a WPF User Interface. Naively, I had assumed that I could simply constantly update a good old fashioned "buffered" System.Drawing.Graphics.Bitmap using Graphics.FromImage. I would draw onto the bitmap the tiles that make up the map, and then blit the buffer Bitmap to the screen. However, from my thorough research I now believe that it isn't that easy at all.
Rather than bore you with what I've found out so far (that either doesn't work, or is incredibly slow), may I ask very simply, what is the best way for continuously drawing large numbers of bitmaps efficiently via a WPF UI?
I will accept such suggestions as "go back to Windows Forms". If that's the case, then I am going to be very dissapointed with WPF!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WriteableBitmap 类是一个高性能的 WPF 兼容位图,允许直接访问其位。 此 MSDN 文档页面包含使用它的完整示例。
The WriteableBitmap class is a high-performance WPF-compatible bitmap that allows direct access to its bits. This MSDN documentation page contains a fairly thorough example of using it.
Freezable 在处理位图时可以对性能产生很大的影响,然后您还可以使用后台线程加载缓冲区以停止 UI 锁定。
本教程涵盖了基础知识
Freezable can make a big difference to performance when dealing with Bitmaps, you can then also load the buffer using a background thread to stop the UI locking up.
This tutorial covers the basics