【请教】GDI+绘图占用CPU资源较高,如何解决?
自己用C#写的控件,主要是用GDI+绘图,感觉效率极差,CPU占用特别高,按照10ms的数据更新速率CPU能占到30%左右了。请高手帮忙看看,该如何优化。
谢谢!!!
代码在
http://download.csdn.net/detail/wsptr/4287188
[解决办法]
配色真够卡哇伊的。。
大概看了下代码,
你的paint里面不断的new和dispose,试试尽量弄成全局变量,减少这种开销。
各种参数能引用的就引用,而不是复制一份。
计算尽量放到paint外面,里面就画图画线就是了。
比如你的黄三角,反正你背景都是一张bmp来旋转,为什么还要在paint里画三角呢,
不如提前画到bmp里,就省了画三角的消耗。。
我的机器i3 4g,空闲10%负载,运行30%(100fps)
好久没整追求性能的了。发现脑瓜空白。。其实以上言论我是瞎掰的。。仅供参考。。
ps.那张巨大的png在哪读取了?图太大了点吧,1000x2000..
[解决办法]
我在想如果用基本图形代替image又会如何呢。。
哈哈,以前我做频谱仪的时候就没搞好性能问题,现在还是半吊子。。
[解决办法]
参考这篇文章
http://www.codeproject.com/Articles/16406/Fast-Drawing-of-Non-32bpp-Images-with-System-Drawi
by J. Dunlap
Fast Drawing of Non-32bpp Images with System.Drawing
It is a well-known fact that when drawing images to the screen that are a different pixel format than the screen's pixel format, format conversion must be performed. GDI+ provides the CachedBitmap class to facilitate easy caching of a converted version of a bitmap. However, this functionality is not exposed in .NET, so normally bitmaps that do not match the screen format are converted on each drawing call.
...
[解决办法]