怎样在web窗体上绘制图形?
一般是生成一个返回图形的aspx文件,然后在页面中插入此图形
简单的说可以绘制以后把它村为一个gif然后显现出来 <%@ Page ContentType = “image/gif”%> <%@ Import Namespace = “System.Drawing” %> <%@ Import Namespace = “System.Drawing.Imaging” %> <Script Runat = “Server”> Sub Page_Load Dim objBitmap As Bitmap Dim objGraphics As Graphics objBitmap = New Bitmap(200, 200) objGraphics = Graphics.FromImage(objBitmap) objGraphics.DrawLine(new Pen(Color.Red), 0, 0, 200, 200) objBitmap.Save(Response.OutputStream, ImageFormat.Gif) objBitmap.Dispose() objGraphics.Dispose() End Sub </Script> |
或者:
void Page_Load(Object sender, EventArgs
e) {
Bitmap bm=new Bitmap(200,200);
Graphics g=Graphics.FromImage(bm);
g.Clear(Color.Yellow);
Pen p=new Pen(Color.Black,1);
Rectangle rect=new
Rectangle(10,10,180,180);
g.DrawEllipse(p,rect);
Brush b1=new SolidBrush(Color.Red);
g.FillPie(b1,rect,0f,190f);
Brush b2=new SolidBrush(Color.Green);
g.FillPie(b2,rect,190f,70f);
Brush b3=new SolidBrush(Color.Blue);
g.FillPie(b3,rect,260f,100f);
bm.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}
e) {
Bitmap bm=new Bitmap(200,200);
Graphics g=Graphics.FromImage(bm);
g.Clear(Color.Yellow);
Pen p=new Pen(Color.Black,1);
Rectangle rect=new
Rectangle(10,10,180,180);
g.DrawEllipse(p,rect);
Brush b1=new SolidBrush(Color.Red);
g.FillPie(b1,rect,0f,190f);
Brush b2=new SolidBrush(Color.Green);
g.FillPie(b2,rect,190f,70f);
Brush b3=new SolidBrush(Color.Blue);
g.FillPie(b3,rect,260f,100f);
bm.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
}