动态生成图片:

服务器:
//首先修改报文头
context.Response.ContentType = "image/png";
//获取用户发送过来的姓名和ip等信息
string strName = context.Request.QueryString["txtName"];//获取用户名
string ip = context.Request.UserHostAddress;//获取ip
//System.Drawing;
using (Image image = new Bitmap(300, 100))//封装GDI位图
{
//无论像图片添加啥内容,都需获取该图片的"画布"
Graphics g=Graphics.FromImage(image);
//设置图片背景色
g.Clear(Color.Pink);
//像图片中写一些字符串:姓名、IP
g.DrawString(strName + Environment.NewLine + ip, new Font("楷体", 20), Brushes.Black, 10,10);
//把创建好的图片发送给用户
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
}
客户端:
<form action="CreateImage.ashx" method="get">
请输入您的大名:<input type="text" name="txtName" value=""/><br />
<input type="submit" value="生成图片"/>
</form>

原文地址:https://www.cnblogs.com/shuai7boy/p/5536850.html