渲染大量重复图像比在 WPF 中使用画笔性能更高还是更低?
我们公司目前正在开发的一个应用程序显示了许多带有渐变的矩形形状来绘制“瓷砖”。内部讨论提出了绩效问题。这些图块大约为 100 像素 x 200 像素,颜色为红色、黄色或绿色渐变。在任何给定时间,屏幕上最多可能有 100 个此类图块。对于我们来说,为每个图像(红色、黄色、绿色)创建一个图像并在需要时重复它会更高效,还是继续使用标准 WPF 画笔绘制它们会更好?
编辑:为了澄清,我们使用的渐变画笔是 LinearGradientBrush。
An application our company is working on currently displays many rectangle shapes with gradients to draw 'Tiles'. An internal discussion came about that posed a question of performance. These tiles are about 100 pixels by 200 pixels, and are either gradient shaded red, yellow, or green. At any given time, there could be up to 100 of these tiles on screen. Would it be more performant for us to create an image for each (red, yellow, green) and repeat it when needed, or would it be better for us to continue drawing them using standard WPF brushes?
EDIT: To clarify, the gradient brush we're using is a LinearGradientBrush.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据经验,使用画笔绘制它们会有更好的性能。与渲染填充矩形相比,加载图块图像并渲染它们的开销很大。
From experience, drawing them using brushes will have far better performance. The overhead of loading up the tile images and rendering them is large compared to rendering filled rectangles.
解决这个问题的唯一方法是尝试两种方法并衡量每种方法的性能。
您需要添加代码来计时渲染循环并将结果记录到文件中,然后强制重绘 1000 次(甚至 100,000 次)才能获得真实的图形。
我的直觉是,LinearGradientBrush 比加载图像(甚至从资源)更快 - 但我愿意被证明是错误的。
The only way to clear this up would be to try it both ways and measure the performance of each approach.
You'd need to add code to time the render loop and log the result to file, then force a 1000 (or even 100,000) redraws to be able to get a realistic figure.
My gut feeling is that the
LinearGradientBrush
would be quicker than loading an image (even from resources) - but I'm willing to be proved wrong.