今天上午的主要任务是搞绘图,搞了一上午,有收获.也有困难.就是不知道如何寻找路径.
代码贴一下,便于以后学习:
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bm = new Bitmap(800, 600);
Graphics g = Graphics.FromImage(bm);
g.Clear(Color.LightBlue);
Pen p = new Pen(Color.Blue, 2);
g.DrawLine(p, new Point(0, 300), new Point(bm.Width, 300));
g.DrawLine(p, new Point(400, 0), new Point(400, bm.Height));
Rectangle rect = new Rectangle(50,150, 50, 50);
Rectangle rect2 = new Rectangle(400, 150, 50, 50);
Rectangle rect3 = new Rectangle(200, 250, 50, 50);
g.DrawEllipse(p, rect);
g.DrawEllipse(p, rect2);
g.DrawEllipse(p, rect3);
g.DrawLine(p, new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), new Point(rect2.X + rect.Width / 2, rect.Y + rect2.Height / 2));
Brush b = new SolidBrush(Color.Red);
Font drawFont = new Font("Arial", 16);
for (int i = 0; i <= 8; i++)
{
g.DrawString(Convert.ToString(i*10), drawFont ,b, new PointF(i*100, 580));
}
for (int j = 0; j <= 6; j++)
{
g.DrawString(Convert.ToString(j * 500), drawFont, b, new PointF(0,600-j*100));
}
bm.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}