PictureBox 有什么更快的地方?许多小重画或完全重画
我有一个 PictureBox (WinMobile 6 WinForm),我在上面画了一些图像。有一个背景图像位于背景中并且不会改变。然而,在图片框上绘制的对象在应用程序期间正在移动,因此我需要刷新背景。
由于重绘的项目填充了表面的 50% 到 80%,因此问题是两者中哪一个更快:
1) 仅重绘背景图像中已更改的部分(移动对象的上一个+下一个位置)。
2) 重新绘制完整的背景,然后将所有对象绘制在当前位置。
现在,之所以问这个问题,是因为我不确定单个drawImage操作需要多少处理器能力以及耗时的因素是什么。
我知道如果背景几乎完全覆盖,那么重新绘制其中的一部分将是愚蠢的,因为通过绘制部分我将绘制完整的图片。但由于有时只有一半的图像发生了变化(某些对象保留在原来的位置),因此仅重绘这些区域可能(也许)是有益的。但我需要你对此的见解...
谢谢。
I have a PictureBox (WinMobile 6 WinForm) on which I draw some images. There is a background image that goes in the background and it does not change. However objects that are drawn on the picturebox are moving during the application so I need to refresh the background.
Since items that are redrawn fill from 50% to 80% of the surface, the question is which of the two is faster:
1) Redraw only parts of the background image that have been changed (previous+next location of the moving object).
2) Redraw complete background and then draw all the objects in their current position.
Now, the reason for asking is because I am not sure how much of processor power is needed for a single drawImage operation and what are the time consuming factors.
I am aware if there is almost complete coverage of the background, it would be stupid to redraw portions of it, because by drawing portions I will have drawn the complete picture. But since sometimes only half of the image had changed (some objects remained in their old position), it may (perhaps) be benefitial to redraw only those regions. But I need your insight on this...
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DrawImage 的数量越少越好,因为它使用 GDI+ 来渲染并且速度非常慢。
我建议使用旧 GDI 的 BitBlt 而不是 DrawImage。
有了这个,您可以将所有必要的部分放入临时画布(图形对象)中,然后将所有内容立即放入 PictureBox 中。如果您在循环中忽略可见屏幕之外的所有部分,那么这应该可以快速运行。
Less number of DrawImage is better, since it uses GDI+ to render and it goes very slow.
I would recommend to use BitBlt of the old GDI instead of DrawImage.
With this you can put all necessary portions to a temporary canvas (Graphics obj) and then put everything into a PictureBox at once. If you ignore in your loop all portions that are outside of the visible screen, this should work fast.