GDI和多层? [英] GDI and multiple layers?

查看:75
本文介绍了GDI和多层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在网站上搜索但没有找到任何内容。

我在OnPaint()和其他一些东西上绘制了1000个多边形。有没有办法加快绘图速度,不是每次都绘制多边形(但仍然可以看到它们)并且只刷新其他东西?



我也使用双缓冲来克服闪烁。

Hi everyone,
I searched the site but didn't find anything.
I have 1000 polygons drawn on OnPaint() and some other stuff. Is there a way to speed up the drawing, by not drawing the polygons every time (but still see them of course) and only "refresh" the other stuff?

I also use double buffering to overcome the flickering.

推荐答案

你当然需要使用双缓冲。加速事物的唯一方法是计算窗口区域的某些点的子集,只计算最近数据更改所触及的那些点,然后调用 InvalidateRect InvalidateRegion 。您可以组合任意数量的不同区域,将它们组合在一起,Windows消息处理机制(对于 WM_PAINT 非常特殊)将在某种程度上优化冗余重绘。请参阅:

http ://msdn.microsoft.com/en-us/library/windows/desktop/dd145002%28v=vs.85%29.aspx [ ^ ],

< a href =http://msdn.microsoft.com/en-us/library/aa769105%28v=vs.85%29.ASPX> http://msdn.microsoft.com/en-us/library/aa769105 %28v = vs.85%29.ASPX [ ^ ]。



但是,如果无效区域不小于此值,则此度量可能效果有限整个场景。



按照他们的方式,你不应该使用刷新之类的东西,你应该只使用invalidate方法。如果你做了一些事情,除了失效,它也可能会严重影响你的表现。



如果我的建议没有多大帮助,你应该批判性地审查你的代码并对其进行优化。一个好的代码分析器可以提供帮助。如果这还不够,那么对于相对较慢的GDI +,您的图形可能太丰富,而且您的性能要求太难了。然后你应该考虑使用DirectX:

http://en.wikipedia.org/wiki/DirectX [ ^ ],

http://www.dmoz.org/Computers/Programming/Libraries/DirectX/ [< a href =http://www.dmoz.org/Computers/Programming/Libraries/DirectX/target =_ blanktitle =New Window> ^ ],

http://www.microsoft.com/en-us/download/details.aspx? id = 6812 [ ^ ],

http:// msdn。 microsoft.com/en-us/library/windows/apps/jj554502.aspx [ ^ ]。



参见: http://msdn.microsoft.com/library/windows/apps/hh452744.aspx [ ^ ]。



-SA
You certainly need to use double buffering. The only one method to accelerate things is to calculate some subset of the points of your window area, only those really touched by your most recent change in data, and call InvalidateRect or InvalidateRegion. You can combine any number of different region, they will be ORed together and the Windows message handling mechanism (very special for WM_PAINT) will, to some extent, optimize out redundant redrawing. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd145002%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/aa769105%28v=vs.85%29.ASPX[^].

However, this measure may have limited effect if the invalidate areas are not much smaller then the whole scene.

By they way, you should not use anything like "refresh", you should only use "invalidate" methods. If you did something except invalidation, it could also affect your performance badly.

If my advice does not help much, you should critically review your code and optimize it. A good code profiler could help. If this is not enough, perhaps your graphics is too rich and your performance requirements are too tough, for the relatively slow GDI+. Then you should think about using DirectX instead:
http://en.wikipedia.org/wiki/DirectX[^],
http://www.dmoz.org/Computers/Programming/Libraries/DirectX/[^],
http://www.microsoft.com/en-us/download/details.aspx?id=6812[^],
http://msdn.microsoft.com/en-us/library/windows/apps/jj554502.aspx[^].

See also: http://msdn.microsoft.com/library/windows/apps/hh452744.aspx[^].

—SA


如果多边形不经常更改我建议使用位图来存储图像,那么你可以使用一个单独的线程来更新图像多边形改变,只显示在油漆上的位图。



这基本上是一种做自己的双缓冲的方法。



(从我的手机上发布)
If the polygons don't change very often I would suggest using a bitmap to store the image then you can use a separate thread to update the image when the polygons change and only display the bitmap in the on paint.

This is basically a method for doing your own double buffering.

(posted from my mobile phone)


这篇关于GDI和多层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆