在 vs2008,用 C# 画多条直线时卡
C#语言,在pictureBox控件中画直线时,数量少画得很快,当数量为100条时执行时间明显长了很多,卡一下才显示所画的100条直线。请大家帮看一下要怎么优化才执行快些?代码如下:程序代码:
Point[] pt; Point p1, p2; List<Point[]> pts = new List<Point[]>(); public void InitData() { int x1, y1, x2, y2; for (int r = 0; r <101; r++) { x1 = 0; y1 = r * 32; x2 = 101* 32; y2 = r * 32; p1 = new Point(x1,y1); p2 = new Point(x2,y2); pt = new Point[2]; pt[0] = p1; pt[1] = p2; pts.Add(pt); } } //调用画图方法 public void myDraw() { Bitmap bmp = new Bitmap(100*32, 100*32); Graphics g = Graphics.FromImage(bmp); Pen pen = new Pen(Color.White, 1); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; foreach (Point[] po in pts) { g.DrawLine(pen, po[0], po[1]); } pictureBox1.Image = bmp; pen.Dispose(); g.Dispose(); }