<%@ Page ContentType = "image/gif"%>
<%@ Import Namespace = "System.Drawing" %>
<%@ Import Namespace = "System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Text" %>
<script runat="server" language="C#">
void Page_Load (Object sender, EventArgs e)
{
Bitmap objBitmap;
Graphics objGraphics;
//建立画布
objBitmap = new Bitmap(400, 440);
objGraphics = Graphics.FromImage(objBitmap);
//填充背景
objGraphics.Clear(Color.White);
//绘制饼状图
Pen p=new Pen(Color.Yellow,0);
Rectangle rect=new Rectangle(10,10,380,380);
objGraphics.DrawEllipse(p,rect);
//填充饼状图
Brush b1=new SolidBrush(Color.Red);
Brush b2=new SolidBrush(Color.Green);
Brush b3=new SolidBrush(Color.Blue);
objGraphics.FillPie(b1,rect,0f,120f);
objGraphics.FillPie(b2,rect,120f,120f);
objGraphics.FillPie(b3,rect,240f,120f);
//绘制文字
FontFamily fontfml=new FontFamily(GenericFontFamilies.Serif);
Font font=new Font(fontfml,20);
SolidBrush brush=new SolidBrush(Color.Blue);
objGraphics.DrawString("ASP.NET C# 绘图示例",font,brush,50,400);
//输出并保存图象
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);
//结束绘制
objBitmap.Dispose();
objGraphics.Dispose();
}
</script>
<html>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)