在c#版发过了,再发一次,关于绘图
再描述一遍整个问题,
有一个csv文档,里面有6万多行,
姑且说是3列吧,为x,y,value,
x,y为坐标值,value为一个数值,
需要做的是根绝这些坐标点绘图,
即绘出6万多个点,可以放大缩小,
并且鼠标移动到点上可以显示value,
先后用过gdi+绘图
Graphics g = Graphics.FromImage(bmp); Pen p = new Pen(Color.Black, 1); g.DrawLine(p, new Point(250, 0), new Point(250, 500)); g.DrawLine(p, new Point(0, 250), new Point(500, 250));
Color c = Color.Blue; Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); int stride = bmpData.Stride; int nOffset = stride - bmp.Width * 4; if (stride != bmp.Width * 4) { throw new Exception("Positive, aligned stride assumption error"); } unsafe { byte* buf = (byte*)bmpData.Scan0; foreach (DataRow dr in dt.Rows) { int x = Convert.ToInt32(dr[0]); int y = Convert.ToInt32(dr[1]); if (Convert.ToDouble(dr[3].ToString()) < 2.2 && Convert.ToDouble(dr[3].ToString()) > 2.1) { c = Color.Black; } if (Convert.ToDouble(dr[3].ToString()) < 2.1 && Convert.ToDouble(dr[3].ToString()) > 1) { c = Color.Yellow; } int argb = (c.A << 24) + (c.R << 16) + (c.G << 8) + (c.B); int* pixel = (int*)(buf + stride * (250- y) + (250 + x) * 4); *pixel = argb; } } bmp.UnlockBits(bmpData);'Form1Option ExplicitPrivate m_Points As PointArrayPrivate Sub DrawPoints() Dim x As Long Dim y As Long Dim value As Double Dim lCount As Long Debug.Print Now(), "DrawPoints(){" Me.Cls With m_Points For x = 0 To .Width - 1 For y = 0 To .Height - 1 value = .Item(x, y) If (2.1 <= value) And (value < 2.2) Then lCount = lCount + 1 Me.ForeColor = vbBlack Me.PSet (x, y) ElseIf (1 <= value) And (value < 2.1) Then lCount = lCount + 1 Me.ForeColor = vbYellow Me.PSet (x, y) End If Next Next End With Debug.Print Now(), , "Count = " & lCount Debug.Print Now(), "}"End SubPrivate Sub Form_Load() Set m_Points = New PointArray m_Points.Initialize Me.ScaleMode = vbPixels Me.AutoRedraw = True Me.BackColor = vbWhite DrawPointsEnd Sub
[解决办法]
单线绘制十万个点无论是怎样绘制对现在的机器来说基本都是秒杀,你的速度慢应该主要是消耗在其它运算上而不是绘图上,你可以用你认为最慢的方法单纯绘制试试,c#再差也不可能像你说的一样,虽然我没用C#,所以你的精力应集中在其它操作的优化上,否则就是直接写屏也会慢;
注:g.DrawLine(p, new Point(250, 0), new Point(250, 500));
不知道你的循环中有多少类似代码,如果多简直就是灾难
无论什么语言,new对象都是要时间开消的,只new一次你可能觉得没什么问题,成千上万次时你试试能节约多少时间,多花点时间优化你的代码吧
放大缩小只是坐标系变换,移动鼠标显示值只是命中测试,都很容易实现