三种方法System.Drawing中表现缓慢图纸或flickery:解决方案?或其他选项? [英] Three System.Drawing methods manifest slow drawing or flickery: Solutions? or Other Options?

查看:169
本文介绍了三种方法System.Drawing中表现缓慢图纸或flickery:解决方案?或其他选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的通过System.Drawing中和IM有几个问题,一个小图形。

I am doing a little graphing via the System.Drawing and im having a few problems.

我手里拿的数据在排队,并且我画(图表)指出,数据到三倍画面框

I'm holding data in a Queue and i'm drawing(graphing) out that data onto three picture boxes

这方法填充,然后在图片框中滚动整个图形。

this method fills the picture box then scrolls the graph across.

所以不吸取以前的图纸之上(并graduly看着混乱),我发现2解决方案,以绘制图形。

so not to draw on top of the previous drawings (and graduly looking messier) i found 2 solutions to draw the graph.


  1. 调用
    plot.Clear(BACKGOUNDCOLOR)平局循环之前[注释块]

  1. Call plot.Clear(BACKGOUNDCOLOR) before the draw loop [block commented]

虽然这会导致闪烁,从它需要做实际的绘制环路的时候才会出现。

although this causes a flicker to appear from the time it takes to do the actual drawing loop.


  1. 调用
    plot.DrawLine(channelPen [5],J,140,J,0); 只是每次的DrawLine [评论]之前

  1. call plot.DrawLine(channelPen[5], j, 140, j, 0); just before each drawline [commented]

虽然这会导致图纸就ok开始,然后仿佛等待命令已被放置平局命令之前非常迅速减速到爬行。

although this causes the drawing to start ok then slow down very quickly to a crawl as if a wait command had been placed before the draw command.

下面是代码,以供参考:

Here is the Code for reference:

/*plotx.Clear(BACKGOUNDCOLOR)

ploty.Clear(BACKGOUNDCOLOR)

plotz.Clear(BACKGOUNDCOLOR)*/

for (int j = 1; j < 599; j++)
            {
                if (j > RealTimeBuffer.Count - 1) break;

                QueueEntity past = RealTimeBuffer.ElementAt(j - 1);
                QueueEntity current = RealTimeBuffer.ElementAt(j);

                if (j == 1)
                {
                    //plotx.DrawLine(channelPen[5], 0, 140, 0, 0);
                    //ploty.DrawLine(channelPen[5], 0, 140, 0, 0);
                    //plotz.DrawLine(channelPen[5], 0, 140, 0, 0);
                }

                //plotx.DrawLine(channelPen[5], j, 140, j, 0);
                plotx.DrawLine(channelPen[0], j - 1, (((past.accdata.X - 0x7FFF) / 256) + 64), j, (((current.accdata.X - 0x7FFF) / 256) + 64));

                //ploty.DrawLine(channelPen[5], j, 140, j, 0);
                ploty.DrawLine(channelPen[1], j - 1, (((past.accdata.Y - 0x7FFF) / 256) + 64), j, (((current.accdata.Y - 0x7FFF) / 256) + 64));

                //plotz.DrawLine(markerPen, j, 140, j, 0);
                plotz.DrawLine(channelPen[2], j - 1, (((past.accdata.Z - 0x7FFF) / 256) + 94), j, (((current.accdata.Z - 0x7FFF) / 256) + 94));


            }

有什么技巧来避免这些开销?

Is there any tricks to avoid these overheads?

如果不是会有其他/更好的解决方案。

If not would there be any other/better solutions?

编辑:参见[最终解决方案]下面的解决方案代码

推荐答案

的PictureBox已经有了双缓冲开启。你可以感觉到闪烁的唯一方法是,当你直接绘制到屏幕上,而不是使用Paint事件中。目前尚不清楚是否从你的片段做。缓冲自己与位图将工作太,但并不像Windows窗体实现双缓冲的高效性能。

PictureBox already has double-buffering turned on. The only way you could perceive flicker is when you draw directly to the screen instead of using the Paint event. It isn't clear whether you do from your snippet. Buffering yourself with a bitmap would work too but isn't as efficient as the double-buffering implemented by Windows Forms.

调用它的invalidate()方法时,数据的变化,做(使用e.Graphics)Paint事件的图纸,它不会闪烁。

Call its Invalidate() method when the data changes, do the drawing in the Paint event (using e.Graphics) and it won't flicker.

这篇关于三种方法System.Drawing中表现缓慢图纸或flickery:解决方案?或其他选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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