本来是想好好学习趁毕设好好学习下JAVA的,但是我JAVA真心不熟,为了开发速度,还是搓搓地选择了用VS2008+C# 了,说实话,这个比java稍微熟一些,但是还是不够熟练,需要好好锻炼自己的代码能力。
纠结了好久的画图代码,原来是因为画点画的太快的缘故,屏幕来不及刷新,必须要用缓存技术。以下为OK代码,就贴下:
public static void Draw_point(PointF point, Color c)
{
Graphics g = Graphics.FromImage(image);
g.FillEllipse(new SolidBrush(c), (float)(point.X - point_size / 2.0), (float)(point.Y - point_size / 2.0), (float)point_size, (float)point_size);
g.DrawString(nodeCount.ToString(), new Font("宋体", 9f), new SolidBrush(c), (float)(point.X - point_size / 2.0), (float)(point.Y - point_size / 2.0 + 5));
nodeCount++;
g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
g.Dispose();
graphics.DrawImage(image, 0, 0);
graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
}
public static void Draw_text(PointF point, string txt, Color c)
{
Graphics g = Graphics.FromImage(image);
g.DrawString(txt, new Font("宋体", 9f), new SolidBrush(c), (float)(point.X - point_size / 2.0), (float)(point.Y - point_size / 2.0 + 10));
g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
g.Dispose();
graphics.DrawImage(image, 0, 0);
graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
}
public static void Draw_line(PointF A, PointF B, Color c,int width)
{
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
g.DrawLine(new Pen(c, width), A.X, A.Y, B.X, B.Y);
g.Dispose();
graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
graphics.DrawImage(image, 0, 0);
}
本文来源:https://www.2haoxitong.net/k/doc/25f6161d14791711cc7917ea.html
文档为doc格式