在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);
'Form1
Option Explicit
Private m_Points As PointArray
Private 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 Sub
Private Sub Form_Load()
Set m_Points = New PointArray
m_Points.Initialize
Me.ScaleMode = vbPixels
Me.AutoRedraw = True
Me.BackColor = vbWhite
DrawPoints
End Sub