改善画布'速度反应

时间:2016-10-25 21:43:33

标签: c# wpf canvas

我的画布有大约70条折线,每条折线都有很多点。在这个画布上我创建了一个mouse_move函数,它的代码很重,但它的工作速度很慢。我尝试使用较少的折线并且其工作更好。 有人可以帮助我提出想法,使mouse_move更好地与所有原始折线一起工作吗? 这是我如何创建每条折线(nStep是10000左右的数字):

for (int j = 0; j < nSteps; j++)
            {
                linesCounter++;
                helpString = rayLines[linesCounter].Split(' ');
                p.X = Convert.ToDouble(helpString[1]);
                p.Y = Convert.ToDouble(helpString[2]);
                beam.Add(p);
            }
            plotRay();

这是我将折线绘制到画布的方式:

private void plotRay()
    {
        double x, y;
        PointCollection fitPoints = new PointCollection();
        for (int i = 0; i < nSteps; i++)
        {
            x =  beam[i].X;
            y = beam[i].Y;
            Point p = new Point();
            p.Offset(x, y);
            fitPoints.Add(p);
        }
        Polyline ray = new Polyline();
        ray = setBrush();
        ray.Points = fitPoints;
        Form.workingCanvas.Children.Add(ray);
    }

这是我的mouse_move方法:

 public void mouseMove(Point currentPos)
    {
        if (firstUse)
        {
            double currentY = Math.Round((currentPos.Y) / (Yresulotion), 2);
            double currentX = Math.Round((currentPos.X) / (Xresulotion), 2);
            Form.WidthLine.Y1 = currentPos.Y;
            Form.WidthLine.Y2 = currentPos.Y;
            Form.HeightLine.X1 = currentPos.X;
            Form.HeightLine.X2 = currentPos.X;
            Form.DotOnGraph.Visibility = System.Windows.Visibility.Visible;
            Canvas.SetLeft(Form.DotOnGraph, currentPos.X -     (Form.DotOnGraph.Width / 2));
            Canvas.SetTop(Form.DotOnGraph, currentPos.Y - (Form.DotOnGraph.Height / 2));
        }
    }

感谢。

0 个答案:

没有答案